断言失败 - [UIApplication _runWithMainScene:transitionContext:completion:],

Aka*_*ani 10 objective-c ios ios9

我只在iOS9中收到以下错误.

这是我的代码: -

- (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];
}
Run Code Online (Sandbox Code Playgroud)

注意:此代码在Xcode 6.4和iOS8中运行良好.

 Assertion failure in -[UIApplication _runWithMainScene:transitionContext:completion:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/UIKit_Sim/UIKit-3505.16/UIApplication.m:3294
Run Code Online (Sandbox Code Playgroud)

And*_*ith 8

我不得不从应用程序didFinishLaunchingWithOptions中删除这一行:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
Run Code Online (Sandbox Code Playgroud)

这就解决了我.


Aka*_*ani 2

在这里,我通过检查 navigationController 是否为零得到了解决方案:-

if (self.navigationController== nil)
{
    self.navigationController = [[BufferedNavigationController alloc] initWithRootViewController:self.firstViewController];
}
else
{
    [self.navigationController setViewControllers:@[self.firstViewController] animated:NO];
}
Run Code Online (Sandbox Code Playgroud)