I instantiate Parse's stock UI Log-in screen via code on an empty VC. I want to then display an AlertController if User's email is not verified. So I'm presenting alertController over logInViewController that I've created by code.... I understand the error that AlertController is not in the window hierarchy, but I'm unsure how to solve it. It works if I dismiss logInViewController but I don't want to, I want it to exist in the background. Using Swift.
This answer did not get to the exact issue: AlertController is not in the window hierarchy
override func viewDidAppear(animated: Bool) {
super.viewDidAppear(animated)
if (PFUser.currentUser() == nil) {
//build logInVC in Code:
var logInViewController = PFLogInViewController()
var logInLogoTitle = UILabel()
logInLogoTitle.text = "Thredz"
logInLogoTitle.font = UIFont(name: "Cochin", size: 40.0)
logInViewController.fields = PFLogInFields.UsernameAndPassword | PFLogInFields.LogInButton | PFLogInFields.SignUpButton | PFLogInFields.PasswordForgotten | PFLogInFields.Twitter
logInViewController.logInView?.backgroundColor = UIColor.whiteColor()
logInViewController.logInView?.logo = logInLogoTitle
logInViewController.delegate = self
//present log in VC
self.presentViewController(logInViewController, animated: true, completion: nil)
//build signUpViewController
var signUpViewController = PFSignUpViewController()
signUpViewController.delegate = self
var signUpLogoTitle = UILabel()
signUpLogoTitle.text = "Thredz"
signUpViewController.signUpView?.logo = signUpLogoTitle
logInViewController.signUpController = signUpViewController
}
}
func logInViewController(logInController: PFLogInViewController, didLogInUser user: PFUser) {
if (PFTwitterUtils.isLinkedWithUser(user)) {
var twitterUsername = PFTwitterUtils.twitter()?.screenName
PFUser.currentUser()?.username = twitterUsername
PFUser.currentUser()?.saveEventually(nil)
}
if user["emailVerified"] as! Bool == true {
dispatch_async(dispatch_get_main_queue()) {
self.performSegueWithIdentifier(self.peopleTableViewControllerSegue, sender: nil)
}
} else {
// User needs to verify email address before continuing
let alertController = UIAlertController(
title: "Email address verification",
message: "We have sent you an email that contains a link - you must click this link before you can continue.",
preferredStyle: UIAlertControllerStyle.Alert
)
alertController.addAction(UIAlertAction(title: "OK",
style: UIAlertActionStyle.Default,
handler: nil)
)
self.presentViewController(alertController, animated: true, completion: nil)
}
}