Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Xcode 7, iOS 9 "Application windows are expected to have a root view controller at the end of application launch"

I got an error in my console and crash.

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

Below is my piece of code, after enter the return YES line crash will happens.

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

    UIImageView *defaultImage = [[UIImageView alloc] initWithImage:splashImage];
    defaultImage.frame = defaultImageFrame;
    [self.window addSubview:defaultImage];

    [NSTimer scheduledTimerWithTimeInterval:3.0 target:self
                                   selector:@selector(login:)
                                   userInfo:nil
                                    repeats:NO];
    [self.window setBackgroundColor:[UIColor clearColor]];
    [self.window makeKeyAndVisible];


    return YES; // here crash will happens
}


-(void)login:(id)sender
{
   PreLoginViewController *appController = [[PreLoginViewController alloc] initWithNibName:nil bundle:nil];
            if (_ChooseLogin.isStatus == 105)
            {
                flagRequired = @"1";
                appController.serverDownFlag = @"1";
            }
            appController.termsURL = _ChooseLogin.urlString;

            appController._ChooseLogin = _ChooseLogin;
            appController.rootNetworkAvailable = NO;
            appController.verionMsg = versionStr;
            [dft setBool:NO forKey:@"isNeedActivate"];
            appController.isNeedActivate = NO;
            navigationController = [[UINavigationController alloc]
                                    initWithRootViewController:appController];

}

Any one know how to fix this issue? its workes fine in iOS 8, upto Xcode 6.3.

like image 701
S P Balu Kommuri Avatar asked Aug 11 '15 06:08

S P Balu Kommuri


1 Answers

You need to call setRootViewController: in your didFinishLaunchingWithOptions: and you need a view controller to do this.

In code:

UIViewController *vc = [[UIViewController alloc] init];
[vc.view addSubview:defaultImage]; 
[self.window setRootViewController:vc];
like image 62
Magic Bullet Dave Avatar answered Nov 09 '22 14:11

Magic Bullet Dave