ios - 解析注册在 Swift 3 中无法正常工作

标签 ios mongodb heroku parse-server

我在 Heroku 和 MongoDB 上部署了一个解析服务器应用程序。在我的 Swift 3 应用程序中,我设置了一个名为 register 的按钮,它运行注册功能:

@IBAction func SignUpBtn(_ sender: UIButton) {
    let user = PFUser()
    user.username = usernameTextField.text
    user.password = passwordTextField.text
    user.email = emailTextField.text
    user["nameandsurname"] = nameandsurnameTextField.text
    user.signUpInBackground {
        (succeeded: Bool, error: Error?) -> Void in

        if error != nil {
            print("error")
            self.errorLabel.text = "Please make sure the email has not already been used or try changing the username"
        } else {
            self.performSegue(withIdentifier: "signuptohome", sender: self)
        }
    }

当我按下按钮时,即使字段为空,按钮也会重定向到主页,让用户使用该应用程序。我该如何解决这个问题?

enter image description here

最佳答案

我的逻辑如下有效。还要确保您没有发生任何您滑入并忘记在您的 Storyboard中的Segues

//this checks 3 fields that they are filled and not empty
     if  passwordTextField.text == "" || emailTxt.text == "" || usernameTextField.text == ""{
            simpleAlert(mess: "You must fill all fields to sign up")
            self.hideHUD()


    } else {
        let user = PFUser()
        user.username = usernameTextField.text
        user.password = passwordTextField.text
        user.email = emailTextField.text

        user.signUpInBackground { (succeeded, error) -> Void in
            if error == nil {
                //success register not lets log him in!!
                PFUser.logInWithUsername(inBackground: self.usernameTextField.text!, password:self.passwordTextField.text!) { (user, error) -> Void in
                    if error == nil {
                      // Here you can go to your logged in or dashboard page!!
                        self.hideHUD()

                    } else {
                        //failed to log user in
                        self.simpleAlert(mess: "\(error!.localizedDescription)")
                        self.hideHUD()
                    }}
            // ERROR
            } else {
                //This will be the failed to register user
                self.simpleAlert(mess: "\(error!.localizedDescription)")
                self.hideHUD()
        }}
}

关于ios - 解析注册在 Swift 3 中无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41088257/

相关文章:

objective-c - 我必须在这里释放 OpenAL 上下文吗?

ios - 检测IOS中uiimageview中的透明像素

ios - MKCircle 平滑调整大小

mysql - 将 MySQL 查询转换为 mongoDB

mongodb - 在 mongodb golang 中保存 session

python - 无法将 Heroku 数据库 pull 到本地

jquery - 500(内部服务器错误)从 JQuery/ajax 到 heroku 服务器的 GET 和请求 POST

postgresql - 连接到我的 RoR 的 Heroku Postgres 数据库?

ios - UIView 动画 vs gif。如果我想获得更好的性能,我应该选择哪一个?

mongodb - mongo objectid 'contains' 查询