以下是本来在使用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了 !!!