Assertion failure in -[UIApplication _runWithMainS

2019-02-12 17:39发布

I am getting the following error in iOS9 only.

Here is my code:-

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{     
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    if ([[NSUserDefaults standardUserDefaults] objectForKey:@"login_dict"])
    {
         if ([[NSUserDefaults standardUserDefaults]  objectForKey:@"isLogout"] == nil || [[[NSUserDefaults standardUserDefaults] objectForKey:@"isLogout"] integerValue]== 0)
         {
            self.loginDict = [[BaseViewController sharedInstance] removeNullFromDictionary:[[NSUserDefaults standardUserDefaults] objectForKey:@"login_dict"]];
            self.firstViewController = [[HomeViewController alloc] initWithNibName:@"HomeViewController" bundle:nil];
         }
         if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"isLogout"] integerValue]== 1)
         {
            self.firstViewController = [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil];
         }
         NSLog(@"Userinfo = %@",self.loginDict);
    }
    else
    {
        self.firstViewController = [[WelcomeViewController alloc] initWithNibName:@"WelcomeViewController" bundle:nil];
    }

    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];

     self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
     self.navigationController = [[BufferedNavigationController alloc] initWithRootViewController:self.firstViewController];
     //[window makeKeyAndVisible];

    [self.window setRootViewController:self.navigationController];
}

Note : This code is working fine in Xcode 6.4 and iOS8.

 Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UIApplication.m:3294

3条回答
走好不送
2楼-- · 2019-02-12 17:54

here i got the solution by checking if navigationController is nil or not:-

if (self.navigationController== nil)
{
    self.navigationController = [[BufferedNavigationController alloc] initWithRootViewController:self.firstViewController];
}
else
{
    [self.navigationController setViewControllers:@[self.firstViewController] animated:NO];
}
查看更多
等我变得足够好
3楼-- · 2019-02-12 18:10

I had to remove this line from application didFinishLaunchingWithOptions:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

And that fixed it for me.

查看更多
放我归山
4楼-- · 2019-02-12 18:19

Using this row solved my issue (iOS 10):

[self.window setRootViewController:self.navigationController];

Was (worked for older iOS and Xcode):

[self.window addSubview:navigationController.view];
查看更多
登录 后发表回答