iOS supportedInterfaceOrientations 循环崩溃

iOS supportedInterfaceOrientations loop crashing

我收到此错误,不知道是什么原因造成的。这在 iOS 8.2 iPhone 和 iPad 上都发生了。

Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_PROTECTION_FAILURE at 0x00554ff4 raw
0 libobjc.A.dylib   lookUpImpOrForward + 3
4 libobjc.A.dylib   -[NSObject respondsToSelector:] + 38
5 UIKit -[UIWindow _supportedInterfaceOrientationsForRootViewController] + 56
6 UIKit -[_UIFallbackPresentationViewController supportedInterfaceOrientations] + 60
7 UIKit -[_UIFallbackPresentationViewController supportedInterfaceOrientations] + 60
...
510 UIKit -[_UIFallbackPresentationViewController supportedInterfaceOrientations] + 60

我读到有人说这应该可以解决这类问题,但没有用。

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    if ( IDIOM == IPAD ) {
        return UIInterfaceOrientationMaskPortrait | UIInterfaceOrientationMaskPortraitUpsideDown;

    } else {
        return UIInterfaceOrientationMaskPortrait;
    }
}

您必须在您的 Viewcontroller

中添加以下方法
-(NSUInteger)supportedInterfaceOrientations{
    return yes for supported orientations
}

下面的代码很适合我。

-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{

return UIInterfaceOrientationMaskLandscape;

} 

如果它没有解决您的问题,我认为您的 代码的其他部分有问题

  • 您可以创建一个空项目并在上面尝试代码 (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window 看看问题是否发生只是为了隔离错误

  • 检查代码中的变量 IDIOMIPAD 是否设置正确

#define IDIOM UI_USER_INTERFACE_IDIOM()

#define IPAD UIUserInterfaceIdiomPad

  • EXC_BAD_ACCESS 是由 非法内存访问引起的 你可能 访问一个被释放的变量

  • 检查所有指针,尤其是对象指针,以确保它们是 初始化。如果您使用的是 xib,请确保您已正确设置, 具有所有必要的连接。

  • 如果 none 有效,则尝试 使用 NSLog() 定位错误 语句并找到导致错误的行,然后 设置 breakpoint and examine all the variables and objects in them to see anything is not本来就是这样。

希望这对您有所帮助。 如果问题还没有解决,请随时问我

我最后就这个问题联系了苹果。据他们说与Game Center有关。苹果改变了它的一些东西,游戏中心初始化的旧方法会产生随机崩溃。在我的游戏中添加了 Game Center Manger,这些随机崩溃停止了。