今天在xcode7上试了一个老项目,装到iOS9出现闪退然后提示这个
Applications are expected to have a root view controller at the end of application launch
百度一下发现说的情况都不符合,赶紧上stackoverflow找到一个答案解决问题。
If you have already set the rootViewController of your self.window in you app delegate and still getting this error at runtime, then you probably have more than one window in your UIApplication one of which may not have a rootViewController associated. You can loop through your app windows and associate an empty viewController to its rootViewController to fix the error you are getting.
Here’s a code that loops through the app windows and associates an empty ViewController to the rootViewController if a window is missing it.
NSArray *windows = [[UIApplication sharedApplication] windows];
for(UIWindow *window in windows) {
NSLog(@"window: %@",window.description);
if(window.rootViewController == nil){
UIViewController* vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
window.rootViewController = vc;
}
}
意思就是应用里有多个UIWindow对象而且有的UIWindow没有设置rootViewcontroller,这时设置一个空Viewcontroller就行。也许是iOS9禁止了没有设置rootViewcontroller的UIWindow所以出现了这样的情况。