IOS9-升级Xcode7后报错Assertion failure in -[UIApplication _runWithMainScene:处理

以下是本来在使用Xcode7时遇到错误的一些解决方案,有网友提供的,也有自己总结的,希望能帮助大家。

错误之

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

这个错误让我一度头疼不已,在网上找了很多方案都没解决,后来自己慢慢的摸索出来的,先给大家分享我自己的解决方案。

解决方案一、不能在
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 方法里面添加引导页代码,(本人就属于这种情况,真TM的坑爹的,苹果不说谁TM知道啊!!!),如下这段代码是添加引导页的,把这段代码注释掉就正常了。
    //xcode7 不能在application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions里面加载启动页,所以下面这段添加引导页的代码应该是要删除的。 切记!切记!  
//    if (![[NSUserDefaults standardUserDefaults]boolForKey:@"everLaunched"]) {  
//        myView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.window.bounds.size.width, self.window.bounds.size.height)];  
//        [myView setImage:[UIImage imageNamed:@"mainPage.png"]];  
//        [self.window.rootViewController.view addSubview:myView];  
//        MiIntroductionViewController *introVC=[[MiIntroductionViewController alloc]initWithNibName:@"MiIntroductionViewController" bundle:nil];  
//        [self.window.rootViewController presentViewController:introVC animated:NO completion:nil];  
//        [[NSUserDefaults standardUserDefaults]setBool:YES forKey:@"everLaunched"];  
//    }else{  
//        [self buildInstoSpecialEdition];  
//    }  
 
 解决方案二、 
新的SDK不允许在设置rootViewController之前做过于复杂的操作,导致在didFinishLaunchingWithOptions 结束后还没有设置rootViewController。(这个方案是网友提供的,但是没解决我的问题),具体做法是,先虚设一个rootViewController,代码如下
//    [self.window makeKeyAndVisible];  
//    UIViewController* myvc = [[UIViewController alloc] initWithNibName:nil bundle:nil];  
//    self.window.rootViewController = myvc;  
 
 解决方案三 
在Info.plist中,可以找到:“Main storyboard file base name”  String “Main”,删掉这个条目, 再启动,屏幕变成了黑屏,然后手动添加window,具体代码如下:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    // Override point for customization after application launch.  
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; //全屏window  
    self.window.backgroundColor = [UIColor whiteColor]; //白色背景  
    [self.window makeKeyAndVisible]; //  
    return YES;  
}  



 上面三种办法,都没有解决我的问题,因为我的window本来就是手动的。 
尝试了网上的办法之后,没有解决问题,最后从错误返回的字面意思解决了。
//    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    rootViewController = [[RootViewController alloc] initWithNibName:@"RootViewController" bundle:nil];
    UINavigationController *navg = [[UINavigationController alloc]initWithRootViewController:rootViewController];
    navg.navigationBarHidden = YES;
    self.window.rootViewController=navg;
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
给window设置主屏幕大小 屏掉 试了一下 就OK了 !!!



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值