1

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;
}
Community
  • 1
  • 1
Swift
  • 397
  • 1
  • 2
  • 11
  • NEVER sleep on the main thread. – rmaddy Nov 22 '16 at 04:27
  • see this http://stackoverflow.com/questions/25963101/unexpected-nil-window-in-uiapplicationhandleeventfromqueueevent – Anbu.Karthik Nov 22 '16 at 04:30
  • @rmaddy I have a launch image. I want it to display for 3 seconds, so I put that. – Swift Nov 22 '16 at 04:31
  • @Anbu.Karthik I tried the solution in that post. Unfortunately, it didn't work for me – Swift Nov 22 '16 at 04:32
  • 1) Again, never sleep on the main thread. 2) Users want to use your app, not stare at a worthless launch image. 3) Never sleep on the main thread. There is a proper solution for what you wish to do. Sleeping is the wrong way. – rmaddy Nov 22 '16 at 04:34
  • @rmaddy Can you tell me how do i show my launch image for atleast 3 seconds without using sleep? – Swift Nov 22 '16 at 04:35
  • 3
    Show the same image in your root controller. Set a timer to go off in 3 seconds. When the timer goes off, remove the image. – rmaddy Nov 22 '16 at 04:36
  • I didn't downvote and it's very unlikely your question was downvoted for sleeping on the main thread. But please note that every single answer that ever suggests sleeping on the main thread is wrong and should not be followed. – rmaddy Nov 22 '16 at 05:09

1 Answers1

0

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.

Swift
  • 397
  • 1
  • 2
  • 11