Old iOS application crashes after launch screen

109 views Asked by At

I'm working on an objective-c iOS application that was first created in 2011 some updates and changes where done in 2013. Now I'm supposed to make this work since it's crashing with an error:

Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Application windows are expected to have a root view controller at the end of application launch'

in AppDelegate i have checked :

[self.window setRootViewController:viewAfterLaunchScreen];

according to this answer "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

after debugging i have noticed that the application crashes after running the rootViewController at viewWillAppear.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
if ([[DAL GetPreferences:@"FIRST"] isEqualToString:@"1"])
{
    LoginViewController *lvc3 = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
    [self.window setRootViewController:lvc3];
    [lvc3 release];
}
else if(_window.rootViewController == nil){

    PagingViewController *lvc2 = [[PagingViewController alloc] initWithNibName:@"PagingViewController" bundle:nil];
    [self.window setRootViewController:lvc2];
    [lvc2 release];
}
[DAL SavePreference:@"FIRST" :@"1"];
[self.window makeKeyAndVisible];
return YES; }
1

There are 1 answers

0
amit_donga On

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];