Reputation: 555
I have a UIAlertViewController that is taking a while to present and by a while its like a second or so.. The code is below.
PFUser.logInWithUsernameInBackground(usernameTextField.text!, password:passwordTextField.text!) {
(user: PFUser?, error: NSError?) in
if user != nil{
self.performSegueWithIdentifier("toMainView", sender: self)
} else {
let alert = UIAlertController(title: "Error", message: "Entered User Creditinials Are Incorrect. Please Try Again.", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "Ok", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in
})
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
}
}
Thank You In Advance :)
Upvotes: 0
Views: 286
Reputation: 38
I changed your code little bit and now UIAlertController popping up instantly. I used Parse.com Error Codes;
PFUser.logInWithUsernameInBackground(usernameTextField.text!, password:passwordTextField.text!) {
(user: PFUser?, error: NSError?) -> Void in
if user != nil {
self.performSegueWithIdentifier("toMainView", sender: self)
} else {
let ErrorCode = error!.code
switch ErrorCode {
case 101:
let alert = UIAlertController(title: "Error", message: "Entered User Creditinials Are Incorrect. Please Try Again.", preferredStyle: UIAlertControllerStyle.Alert)
let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:{ (action: UIAlertAction!) in })
alert.addAction(action)
self.presentViewController(alert, animated: true, completion: nil)
break
default:
println(ErrorCode)
break
}
}
}
You can see Parse Error Codes here.
Upvotes: 1