"Application windows are expected to have a root view controller at the end of application launch" error when running a project with Xcode 7, iOS 9
Solution 1:
From your error message:
Application windows are expected to have a root view controller at the end of application launch
How old is this "old" project? If it's more than a few years, do you still have:
[window addSubview:viewController.view];
You should instead replace it with:
[window setRootViewController:viewController];
Solution 2:
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;
}
}
Update: Apparently there is a window dedicated to the status bar which typically causes this issue. The above code should fix this error.