1

My app sends a request at startup and displays a brief message to users when it succeeds, by means of MTStatusBarOverlay. Unfortunately, my current implementation seems to run afoul of iOS 9's view life cycle paradigms. I get the message

Application windows are expected to have a root view controller at the end of application launch

and the app crashes. The app works fine on iOS 7 & 8.

From searching around online, it seems like this might occur when trying to add the message view to the view hierarchy before the root view controller is established for the app's UIWindow, but that doesn't seem to be the case here, see below.

Here is an excerpt of the UIApplicationDelegate implementation:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [...]

    self.window.rootViewController = [[MyViewController alloc] init];

    [...]
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [MyDataManager sendRequestWithCompletion:^{
        // Displays a message with MTStatusBarOverlay
        [self showSuccessOverlay];
    }];
}

application:didFinishLaunchingWithOptions: is called before applicationDidBecomeActive: so it seems like there should never be an issue with rootViewController being established.

Why is this happening? What's different about iOS 9 that's causing the app to break?

aednichols
  • 2,292
  • 2
  • 19
  • 28
  • Possibbly related to this issue https://forums.developer.apple.com/thread/7074. Also you can check this thread http://stackoverflow.com/questions/30884896/application-windows-are-expected-to-have-a-root-view-controller-at-the-end-of-a – mkeremkeskin Nov 19 '15 at 00:12

1 Answers1

1

MTStatusBarOverlay is a subclass of UIWindow, so instantiating one during app launch adds that UIWindow to the list that iOS checks for a populated rootViewController when launch completes.

I was able to work around the issue by instantiating and assigning a dummy controller before using the overlay, like so:

[MTStatusBarOverlay sharedInstance].rootViewController = [UIViewController new];
[[MTStatusBarOverlay sharedInstance] postMessage:@"Message"];
aednichols
  • 2,292
  • 2
  • 19
  • 28