unexpected nil window in _UIApplicationHandleEventFromQueueEvent, _windowServerHitTestWindow
Asked Answered
H

7

12

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?

Honeyman answered 6/10, 2014 at 23:11 Comment(3)
possible duplicate of unexpected nil window in _UIApplicationHandleEventFromQueueEventRetentive
@SantaClaus Sorry but that other issue you linked to does not fix my issue as I have tried it. Mine is a different issue.Honeyman
See this question. There is a simple one-click Interface Builder fix to this problem in many cases, especially with "heritage" apps.Ahmed
A
10

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];
Allman answered 19/10, 2014 at 16:28 Comment(3)
I have exactly the same issue - only on my iPad Mini running iOS 7 and up - my iPad 3 doesn't seem to suffer the same issue, but that's still on iOS 6...Michaels
@Michaels Interesting. My testing of this issue is done on an iPad 3 running iOS 8.Honeyman
Note that the entire view hierarchy from window to the view with the attached screen edge pan gesture recogniser needs to have the bumped size, otherwise the gesture recogniser doesn't trigger.Sideling
T
8

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.

Tomi answered 4/12, 2014 at 12:30 Comment(3)
@Lapiou : Can you both explain more as my view controller don't have xib so have can i do it ????Eec
@Prince Maybe try in your app delegate, in your didFinishLaunchingWithOptions: self.window.hidden = YES;Tomi
'navigationController' not found for objectAngwantibo
K
7

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) )

Kalidasa answered 21/11, 2014 at 18:41 Comment(1)
Exact same situation here - trying to test iPhone app on iPad with 2x mode (pure iPhone app, not universal)Angwantibo
S
3

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
Sideling answered 21/4, 2015 at 4:18 Comment(0)
B
2

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 -> */
Burden answered 15/1, 2015 at 17:18 Comment(0)
V
1

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

Done!

Visional answered 21/4, 2016 at 0:8 Comment(1)
Whilst this may theoretically answer the question, it would be preferable to include the essential parts of the answer here, and provide the link for reference.Noontide
H
1

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

Hime answered 20/8, 2016 at 12:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.