EXC_BAD_ACCESS / KERN_INVALID_ADDRESS associated with orientation changes

I have a strange problem. I received an error message stating that the application crashed due to a change in orientation. The problem is that I did not subscribe to any indicative events in the application code at all. The only thing related to changing orientation changes:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { return IS_IPAD ? YES : interfaceOrientation == UIInterfaceOrientationPortrait; } 

... on all view controllers, so that it changes orientation on the iPad, but not the iPhone. And the error occurred on the iPhone.

IS_IPAD comes from this:

 #ifdef UI_USER_INTERFACE_IDIOM #define IS_IPAD (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) #else #define IS_IPAD (false) #endif 

It seems that -[UIWindow _updateInterfaceOrientationFromDeviceOrientation:] calls some object that no longer exists. What can be an object if I am not registered for any orientation related notifications?

enter image description hereenter image description here

+4
source share
3 answers

The stack trace shows that the NSNotificationCenter trying to notify the object, apparently, of a change in orientation. You may have registered such an object, but it is no longer there, and it was not unregistered until release. This could lead to such an error.

-1
source

If you are running iOS 6 or later, you also need to implement the following methods:

 // Support iOS 6 - (BOOL)shouldAutorotate { return IS_IPAD ? YES : NO; } // Support iOS 6 - (NSUInteger)supportedInterfaceOrientations { return IS_IPAD ? UIInterfaceOrientationMaskAll : UIInterfaceOrientationMaskPortrait; } 

Check to see if this issue resolves the issue.

-1
source

The method used is out of date. The shouldAutorotate method is a new way to support autorotation. I tried this and it worked the way you want:

 -(BOOL) shouldAutorotate{ return IS_IPAD ? YES : [self preferredInterfaceOrientationForPresentation] == UIInterfaceOrientationMaskPortrait; } 

Hope this helps :)

-2
source

All Articles