I want to present a modal view controller (for a login screen) when my app launches, and also when it becomes active again after a user has hit the home button and then relaunched the app.
I first tried to present the modal view in the root view controller's viewDidAppear:
method. That works great when the app first launches, but this method isn't called when the app becomes active again.
- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self presentModalView];
}
- (void)presentModalView {
if(![AuthenticationService sharedInstance].isAuthenticated) {
_modalVC = [self.storyboard instantiateViewControllerWithIdentifier:self.modalViewControllerIdentifier];
_modalVC.delegate = self;
[self presentViewController:_modalVC animated:YES completion:nil];
}
}
Next I tried to call this from my app delegate in the applicationDidBecomeActive:
method.
- (void)applicationDidBecomeActive:(UIApplication *)application
{
// 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.
ModalPresentingUISplitViewController *splitViewController = (ModalPresentingUISplitViewController *)self.window.rootViewController;
[splitViewController presentModalView];
}
This appears to work fine on the surface, but I get a Unbalanced calls to begin/end appearance transitions for <ModalPresentingUISplitViewController: 0x7251590>
warning in my log. I get the sense that I'm somehow presenting the modal view before the UISplitView is finished presenting itself, but I don't know how to get around this.
How can I "automatically" present a modal view from my root view controller when the app becomes active, and do it at the "right" moment as not to unbalance my split view controller?