我试图在用户创建帐户时如此...如果他们的电子邮件尚未在“警告”框显示“创建帐户”之前使用,并且电子邮件已在创建中(在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)
}
}
}
答案 0 :(得分: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
}