Search code examples
iosswiftparse-platform

Parse Log In Error doesn't pop up


I'm developing an iPhone app with Swift using Parse. I've created a simple log in screen using Parse's PFLoginViewController. There are pop ups (UIAlertControllers) when the user does things like signing up without a username etc, but there is no pop up for when the log in credentials are invalid. Instead I just get an error in the console:

2015-08-23 22:50:10.246 SwifferApp[24429:1614072] [Error]: invalid login parameters (Code: 101, Version: 1.8.1)

I have a function for when the log in fails, but I can't present the UIAlertController over the PFLoginViewController

 func logInViewController(logInController: PFLogInViewController, didFailToLogInWithError: NSError?){

        var invalidCredentials = UIAlertController(title: "Invalid Credentials", message: "Incorrect username or password.", preferredStyle: UIAlertControllerStyle.Alert)

        invalidCredentials.addAction(UIAlertAction(title: "Okay", style: .Default, handler: { (action: UIAlertAction!) in
            //do nothing
        }))

        presentViewController(invalidCredentials, animated: true, completion: nil)
    }

On the line with "presentViewController" i get the error

2015-08-23 22:50:10.249 SwifferApp[24429:1613783] Warning: Attempt to present <UIAlertController: 0x7c1f1a50> on <SwifferApp.TimelineTableViewController: 0x7c1b7120> whose view is not in the window hierarchy!

What can I do to include a log in error pop up?


Solution

  • Figured it out!

    All I need to do was replace

    presentViewController(invalidCredentials, animated: true, completion: nil)
    

    with

    logInViewController.presentViewController(invalidCredentials, animated: true, completion: nil)