Swift Swift - 8 days ago 6
iOS Question

AppDelegate "unexpected nil window' error

EDIT:
People downvoting this because I used sleep, this is why I used it:

Making the launch image display longer xcode

The window size is small. If you don't want to answer, don't downvote it.
I just want to get rid of this error.


unexpected nil window in _UIApplicationHandleEventFromQueueEvent,
_windowServerHitTestWindow: UIClassicWindow: ; frame = (0 0; 320 568); userInteractionEnabled = NO; gestureRecognizers = NSArray: > ; layer =
UIWindowLayer: >>





I have an iOS app which runs on both iPad and iPhone in landscape mode. It runs fine on the ipad simulators but on the iphone 5s and iphone 6s (which I have tested so far), I get this error:


unexpected nil window in _UIApplicationHandleEventFromQueueEvent,
_windowServerHitTestWindow: UIClassicWindow: ; frame = (0 0; 320 568); userInteractionEnabled = NO; gestureRecognizers = NSArray: > ; layer =
UIWindowLayer: >>


This is the AppDelegate code.. I don't have any problem on ipad.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

// [NSThread sleepForTimeInterval:3];

[application setStatusBarHidden:YES];
self.window = [UIWindow new];

if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad) {

self->_loginViewController = [[LoginViewController alloc] initWithNibName:@"somename~ipad" bundle:nil];

} else if([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPhone) {

self->_loginViewController = [[LoginViewController alloc] initWithNibName:@"somename~iphone" bundle:nil];
}

[[NSUserDefaults standardUserDefaults] setValue:@(NO) forKey:@"_UIConstraintBasedLayoutLogUnsatisfiable"];

self.window.rootViewController = nil;
self.window.rootViewController = self->_loginViewController;

[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTranslucent:NO];

[self.window makeKeyAndVisible];
[self.window setFrame:[[UIScreen mainScreen] bounds]];
return YES;
}

Answer

I figured out that I was getting the "unexpected nil window" error because I was using Asset catalog for my landscape application.

https://developer.apple.com/library/content/technotes/tn2244/_index.html#//apple_ref/doc/uid/DTS40009012

Avoid using asset catalogs to manage the launch images of landscape applications. Except for launch images used by the iPhone 6 Plus, asset catalogs assume that all iPhone launch images are for the portrait orientation.

Comments