我希望我的應用程序能夠在沒有正確憑證的情況下阻止用戶登錄(與其他應用程序非常相似)。我正在使用Parse並在他們的iOS源代碼文檔中使用他們的代碼作爲登錄序列,但只要我登錄按鈕時沒有任何憑據,甚至是錯誤的登錄按鈕,它仍然適用於sucessfulLoginPage segue標識符,而不先檢查其憑據。我已經嘗試過所有我知道如何去做而沒有取得任何成功的人,有沒有人可以幫助我呢?下面我有我的代碼。解析沒有有效的郵票的登錄過程
PFUser.logInWithUsernameInBackground(username, password:password) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
self.performSegueWithIdentifier("sucessfulLoginPage", sender: self)
} else if username.isEmpty || password.isEmpty {
var emptyFieldsError:UIAlertView = UIAlertView(title: "Please try again", message: "Please fill in all the fields we can get you logged in to your account.", delegate: self, cancelButtonTitle: "Try again")
emptyFieldsError.show()
self.loginActivity.hidden = true
self.loginButton.userInteractionEnabled = true
self.loginButton.alpha = 1.0
self.loginActivity.stopAnimating()
self.usernameField.userInteractionEnabled = true
self.passwordField.userInteractionEnabled = true
self.forgotPasswordLabel.userInteractionEnabled = true
} else {
self.loginActivity.hidden = true
self.loginButton.userInteractionEnabled = true
self.loginButton.alpha = 1.0
self.loginActivity.stopAnimating()
self.usernameField.userInteractionEnabled = true
self.passwordField.userInteractionEnabled = true
self.forgotPasswordLabel.userInteractionEnabled = true
var invalidLogin:UIAlertView = UIAlertView(title: "Please try again", message: "The username password combo you gave us does not match our records, please reset your password or try again.", delegate: self, cancelButtonTitle: "Try again")
invalidLogin.show()
}
}
也許是因爲'user'不是'nil'? –