sonali
sonali

Reputation: 165

Xcode 7 beta ios 9 giving error 'Application windows are expected to have a root view controller at the end of application launch'

This is my code . I am using MTStatusBarOverlay too.This code works properly when run using xcode 6. Application crashing and giving error

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

I have tried to set rootViewController in many different manners. I even tried overriding following code in MTStatusBarOverlay

     - (UIViewController *)rootViewController {
         ETAppDelegate *delegate = (ETAppDelegate *)[UIApplication sharedApplication].delegate;
         return delegate.window.rootViewController;
     }


     - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{
         _didReceiveBackgroundNotification = NO;


         [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeBadge];

         NSDictionary *remoteNotification = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];

         MTStatusBarOverlay *overlay = [MTStatusBarOverlay sharedInstance];
         overlay.animation = MTStatusBarOverlayAnimationNone;
         overlay.hidesActivity = YES;

         NSDictionary *bundleDictionary = [[NSBundle mainBundle] infoDictionary];
         NSString *currentVersion = [NSString stringWithFormat:@"%@ (%@)", [bundleDictionary objectForKey:@"CFBundleShortVersionString"], [bundleDictionary objectForKey:@"CFBundleVersion"]];

        [overlay postMessage:@"Test Application" stringByAppendingString:currentVersion]];

        [self.window makeKeyAndVisible];

        return YES;
    }



    - (UIWindow *)window{
       if (_window) return _window;

       _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
       [_window setRootViewController:self.rootViewController];

       return _window;
  }


  - (UIViewController *)rootViewController{
       if (_rootViewController) return _rootViewController;
       _rootViewController = [[ETNavigationController alloc] initWithNibName:nil bundle:nil];

       ETHomeMenuViewController *homeViewController = [[ETHomeMenuViewController alloc] initWithNibName:nil bundle:nil];
                  ((ETNavigationController*)_rootViewController).rootViewController = homeViewController;
      homeViewController = nil;
      return _rootViewController;
 }

Upvotes: 3

Views: 389

Answers (1)

korovyev
korovyev

Reputation: 34

Because MTStatusBarOverlay is a subclass of UIWindow, and Xcode 7 now specifies as the error message says:

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

This means you cannot instantiate a UIWindow without a root viewcontroller before application launch. So don't call [MTStatusBarOverlay sharedInstance] until after the application has launched.

Upvotes: 1

Related Questions