Search code examples
iosswiftparse-platformalertview

AlertViewController in Parse


I am using the Parse login controller (default Parse one they offer) to implement a user login/pass for my app. It works fine, I am able to log in, register, and the whole thing.

The only thing is that I want to add an alert if the password is wrong, right now it only println("Failed to login...") when the password is wrong, and the user has no idea that their password is wrong. I added an alert, but some reason it isn't appearing. The error message I get is:

Warning: Attempt to present <UIAlertController: 0x1a06d5d0> on <Snappraisal.MainViewController: 0x15e58290> whose view is not in the window hierarchy!

Here is the alert I added to my code:

func logInViewController(logInController: PFLogInViewController!, didFailToLogInWithError error: NSError!) {
    println("Failed to login...")
    let alertView = UIAlertController(title: "Failed to login...", message: "Incorrect password or username.", preferredStyle: .Alert)
    alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil))
    presentViewController(alertView, animated: true, completion: nil)

}

I think it might be because the parse default login screen I am using that they provided is not on my storyboard, but called from the Parse framework(?). How do I go about adding an alert view?


Solution

  • Try this

    logInController.presentViewController(alertView, animated: true, completion: nil)
    

    I think parse displays an alert when you log in with invalid credentials, so this might show 2nd - after there alert is dismissed.