0

我正在尝试拥有它,因此当用户创建帐户时...如果在出现“已创建帐户”的警报框之前尚未使用他们的电子邮件,并且如果已创建电子邮件(在 Parse 上),则发出警报应该出现通知用户。

我似乎无法让我的代码同时执行这两项操作..只显示一条消息。我在这里做错了什么?

谢谢!

func createNewUser() {

    let newUser = PFUser()
    newUser.email = emailSignUp.text
    newUser.username = emailSignUp.text
    newUser.password = passwordSignUp.text

    newUser.signUpInBackgroundWithBlock { ( success: Bool, error: NSError?) -> Void in


       if newUser.username != nil {


        let alert: UIAlertController = UIAlertController(title: "Account created", message: "Please confirm your email", preferredStyle: .Alert)

        let okButton = UIAlertAction(title: "OK", style: .Default) { action -> Void in
        }

        alert.addAction(okButton)
        self.presentViewController(alert, animated: true, completion: nil)

       }
       else {

        let alert: UIAlertController = UIAlertController(title: "Email already registered", message: "Please enter a different email", preferredStyle: .Alert)

        let okButton = UIAlertAction(title: "OK", style: .Default, handler: nil)

        alert.addAction(okButton)

        self.presentViewController(alert, animated: true, completion: nil)
        }
    }
}
4

1 回答 1

0

如果内存服务于用户已存在时返回的错误,则该字符串与一般错误不同。您可以尝试匹配错误字符串,然后在匹配时显示警报,如果只是错误(如错误字符串本身)则显示不同的警报。

newUser.signUpInBackgroundWithBlock { ( success: Bool, error: NSError?) -> Void in

if error != nil {

    if let errorString = error.userInfo?[“error”] as? String {

        if errorString == “username \(emailSignUp.text) already taken” {

            // Create alert that address is taken           
        } else {

            // Create other case alert, though it may make sense to just display the error string in an alert box
        }

    }

} else {

// Do your usual stuff

}
于 2015-07-24T00:29:02.130 回答