I'm checking to see if a user is logged in. If logged in, then skip the LoginViewController (Initial View Controller), and head over to the MainViewController.
I've tried doing this check within LoginViewController in countless places of the lifecycle without the under-layer flashing.
By under-layer flashing, I mean you can see the LoginViewController for a split second before the MainViewController comes up.
I have solved this 1 way, but it feels extremely hacky:
In my LoginViewController:
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
calls++
if calls == 2 && NSUserDefaults.standardUserDefaults().objectForKey("AuthToken") != nil {
self.performSegueWithIdentifier("loginUserNoAnim", sender: self)
}
}
The "loginUserNoAnim" is a custom Segue I created with no animation.
viewDidLayoutSubviews()
gets called in my code 3 times. The first two times, I get warnings that my ViewController is not in the window hierarchy similar to this: Warning: Attempt to present <PSLoginViewController: 0x1fda2b40> on <PSViewController: 0x1fda0720> whose view is not in the window hierarchy!
This creates a two extremely quick white flashes in the UI. I got rid of them by checking how many calls were made via the call
variable.
Now, this is 100% hacky and not acceptable.
Is there a way to solve this issue by using the iOS lifecycle? I've even tried using the appdelegate method:
func applicationDidBecomeActive(application: UIApplication) {
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
}
But I still saw the under-layer flash. What is the best way to mitigate it?