I want to display a modal view controller to the user should there not be a user logged in. Here is my method implementation:
func application(application: UIApplication, willFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool
{
// Notifications
//
// User
//
NSNotificationCenter.defaultCenter().addObserver(self, selector: "noCurrentUser:", name: UserCurrentUserNotSetNotificationName, object: nil)
NSNotificationCenter.defaultCenter().addObserver(self, selector: "currentUserDidChange:", name: UserCurrentUserDidChangeNotificationName, object: nil)
// Root window
//
if managedObjectContext != nil && User.currentUser(managedObjectContext!) == nil
{
let storyboard = UIStoryboard(name: "Main", bundle: nil)
if let logInViewController = storyboard.instantiateViewControllerWithIdentifier("Log In View Controller") as? LogInViewController
{
window?.rootViewController?.presentViewController(logInViewController, animated: false, completion: nil)
}
}
return true
}
I include the notifications because currently, the noCurrentUser:
method presents my log in view controller modally and animated. This works well except when the app launches, the user sees a flash of the app (the root view controller) before the the notification is sent and the modal log in view controller is presented.
I’ve tried setting the modal animation option to false on presenting, but because it’s not the root view controller, this still doesn’t work.
So how do I properly set a root view controller to a modal view controller which I can then dismiss modally.