2016-05-10 58 views
0

我讓用戶使用parse來註冊系統,但即使有一個字符串傳遞給PFUser的用戶名屬性,它也會一直說「無法用戶名無法註冊」。什麼導致這個錯誤?解析「無法註冊用戶名」

  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

你有實際分配這些屬性,你叫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 
} 
} 
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 
    }