motionpotion
motionpotion

Reputation: 2736

unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow

I am trying to set up an edge swipe gesture in iOS 8 on iPad but getting and error that seems like a bug.

I have the following code:

    UIScreenEdgePanGestureRecognizer *edgeRecognizer = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleRightEdgeSwipe:)];
edgeRecognizer.edges = UIRectEdgeRight;
[self.view addGestureRecognizer:edgeRecognizer];

and then I handle the gesture:

-(void)handleRightEdgeSwipe:(UIGestureRecognizer*)sender
{
//slide in view code here
}

The problem is that it doesn't detect the right edge swipe every time. And sometimes it detects it multiple times.

Whether it detects or not it always shows the following information in the console when swiping the right edge on iPad:

2014-10-07 00:04:40.386 Office Log[1531:500896] unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: ; layer = >

What does this message mean and how can I fix it so that the right edge swipe is detected consistently?

Upvotes: 12

Views: 17521

Answers (7)

Aragunz
Aragunz

Reputation: 501

It may be to late but some people may still need it, normally the cause is that you haven't supplied correctly sized launch images or a launch screen and/or Main Interface is not set to your own storyboard at General> Deployment Info

Upvotes: 1

RichIntellect
RichIntellect

Reputation: 291

Set your deployment to 8.x or above, set launch screen as your main xib.

Done!

Upvotes: 1

Glen Low
Glen Low

Reputation: 4497

iOS 8 has a bug where any touch that begins exactly on an iPad right edge when in Portrait Upside-Down (home button on top) or Landscape Left (home button on left) mode fails to be hit tested to the correct view.

The fix is to subclass UIWindow to hit test the right side properly.

@implementation FixedWindow

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
  UIView* hit = [super hitTest:point withEvent:event];
  if (!hit && point.x >= CGRectGetMaxX(self.bounds))
    hit = [super hitTest:CGPointMake(point.x - 0.5, point.y) withEvent:event];
  return hit;
}

@end

Attach the window to your application delegate via the window property.

@implementation AppDelegate

- (UIWindow*)window
{
  if (!_window)
    _window = [[IVWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];
  return _window;
}

@end

In Portrait and Landscape Right modes, I've confirmed that right edge touches are always at least 0.5px from the edge instead of exactly on the edge, so this fix should work in analogy to that.

Expanding the window frame

Note that firebug's fix will also work i.e. slightly expanding the window frame to include the right side. However:

  • If you do this at application:willFinishLaunchingWithOptions: or application:didFinishLaunchingWithOptions:, your view hierarchy doesn't get resized to the new frame and right edge touches won't make it through the hierarchy.
  • If you rotate the device, the window may not be centered correctly. This leads to either smearing or bumping interface elements slightly.

iOS 7:

iOS 7 has a similar bug in that the hit test also fails but with a non-nil result and unrotated geometry. This fix should work with both iOS 7 and 8:

@implementation FixedWindow

- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent*)event
{
  UIView* hit = [super hitTest:point withEvent:event];
  if (!hit || hit == self)
  {
    CGRect bounds = self.bounds;
    hit = [super hitTest:CGPointMake(MIN(MAX(point.x, CGRectGetMinX(bounds) + 0.5), CGRectGetMaxX(bounds) - 0.5),
                                     MIN(MAX(point.y, CGRectGetMinY(bounds) + 0.5), CGRectGetMaxY(bounds) - 0.5))
               withEvent:event];
  }
  return hit;
}

@end

Upvotes: 3

Lapinou
Lapinou

Reputation: 1477

I got the same issue. My solution works fine: just set in your xib your Windows to hidden.

I don't really understand why it works, but it works.

EDIT 1:

I found another solution, better I think, and more understandable:

Put this code on your willFinishLaunchingWithOptions, in your appDelegate:

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

    CGRect bounds = [[UIScreen mainScreen] bounds];
    [self.window setFrame:bounds];
    [self.window setBounds:bounds];

    return YES;
}

Then, on your didFinishLaunchingWithOptions:

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

    // Your codes...

    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];

    return YES;
}

Your can then set your window object hidden to NO, and it should works.

Upvotes: 8

Gillsoft AB
Gillsoft AB

Reputation: 4225

One possible fix is to remove or comment out code for hiding status bar if you have that. I was pulling my hair to solve it, and I could only reproduce it on my root view. It appears that if you hide the status bar you cannot drag down today widgets/notification center (you can with some effort).

/* <- add this
- (BOOL)prefersStatusBarHidden
{
   return YES;
}
add this -> */

Upvotes: 2

Leszek Zarna
Leszek Zarna

Reputation: 3317

I got issue when testing iPhone app on iPad. No problems on simulator and no problem if I compile app as universal and run on iPad.

unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow: <UIClassicWindow: 0x1276065a0; frame = (0 0; 768 1024); userInteractionEnabled = NO; gestureRecognizers = <NSArray: 0x1740557e0>; layer = <UIWindowLayer: 0x17403fd80>>

Perhaps frame is reported wrong ? ( frame = (0 0; 768 1024) )

Upvotes: 7

firebug
firebug

Reputation: 160

I think it's a bug in iOS, which I can confirm on an iPad mini 2 and an iPad Air on iOS 7 or higher, even on the Home Screen.

In "Landscape Left" (Home button on the left) a "Right Edge Gesture" from outside the Screen is not working for me. Test it by your self on the Home Screen.

I reported a bug to Apple 9 Month ago, but noting further happened.

Update:

I played a bit with the UIWindow init and when it is a bit bigger than it really is, the Gesture works. Of course this is a horrible fix.

self.window = [UIWindow new];
self.window.rootViewController = [[UIViewController alloc] init];

// Real Size
CGRect frame = [UIScreen mainScreen].bounds;

// Real Size + 0.000001
self.window.frame = CGRectMake(0, 0, frame.size.width+0.000001, frame.size.height+0.000001);
[self.window makeKeyAndVisible];

Upvotes: 10

Related Questions