我收到此错误,但不知道可能导致它的原因。这在iPhone和iPad上的iOS 8.2中都发生了。
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;
}
}
我最终就此问题联系了苹果。据他们说,与游戏中心有关。苹果改变了它的一些东西,游戏中心的旧初始化方式会产生随机崩溃。在我的游戏中添加了一个游戏中心管理器,这些随机崩溃停止了。
下面的代码对我很好用。
-(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window{
return UIInterfaceOrientationMaskLandscape;
}
如果它没有解决你的问题,我认为你的代码的其他一些部分是错误的。
您可以创建一个空项目并尝试
(NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
的代码,看看问题是否只是为了隔离窃听器检查变量 IDIOM 和 IPAD 在代码中是否正确设置
#define 成语 UI_USER_INTERFACE_IDIOM()
#define IPAD UIUserInterfaceIdiomPad
EXC_BAD_ACCESS是由非法内存访问引起的,您可能正在访问已解除分配的变量。
检查所有指针,尤其是对象指针,以确保它们是初始 化。如果您使用的是 xib,请确保已正确设置,具有所有必要的连接。
如果这些都不起作用,请尝试使用 NSLog() 定位错误语句并找到导致错误的行,然后设置断点并检查其中的所有变量和对象以查看任何内容都不是它应该的样子。
希望这有帮助。如果问题仍未解决,请随时询问我
您必须在视图控制器中添加以下方法
-(NSUInteger)supportedInterfaceOrientations{
return yes for supported orientations
}