我使用parse创建了一个用户注册系统,但即使有一个字符串传递给PFUser的username属性,它仍然会说“无法在没有用户名的情况下注册”。是什么导致了这个错误?
let user = PFUser()
user.signUpInBackgroundWithBlock{(success:Bool,error:NSError?)-> Void in if error==nil{
user.username = self.username.text!
user.password=self.Password.text!
user.email=self.Email.text!
self.navigationController?.pushViewController(UploadImageViewController(),animated:true)
}
else {let errorMessage: String = error!.userInfo["error"] as! String;self.displayErrorMessage(errorMessage)}
}
答案 0 :(得分:0)
在致电signUpInBackgroundWithBlock
这样的事情:
let user = PFUser()
user.username = self.username.text!
user.password=self.Password.text!
user.email=self.Email.text!
user.signUpInBackgroundWithBlock {
(succeeded: Bool, error: NSError?) -> Void in
if let error = error {
let errorString = error.userInfo["error"] as? NSString
// Handle the error
} else {
// Push your view controller
}
}
答案 1 :(得分:0)
您应该在尝试注册用户之前设置这些属性。
let user = PFUser()
user.password = password.text
user.username = username.text
//add other properties you might want
user.signUpInBackgroudWithBlock{(success: Bool, error: NSError?) -> in
if success && error == nil {
//success
} else {
//error
}