ios6.0横竖屏幕导致的崩溃

项目中遇到的一个头疼的问题。

在ios6.0的模拟器上一启动就会崩溃,第一个界面刚刚显示出来就崩溃,项目是cocos2d的项目,cocos2d的版本位cocos2d-iphone-2.1-rc1。崩溃后的log显示:Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

网上也有很多人有遇到这个错误的,大家给出的答案大部分都是


-(NSUInteger)supportedInterfaceOrientations {
	
	// iPhone only
	if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
		return UIInterfaceOrientationMaskLandscape;
	
	// iPad only
	return UIInterfaceOrientationMaskLandscape;
}

// Supported orientations. Customize it for your own needs
// Only valid on iOS 4 / 5. NOT VALID for iOS 6.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
	// iPhone only
	if( [[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone )
		return UIInterfaceOrientationIsLandscape(interfaceOrientation);
	
	// iPad only
	// iPhone only
	return UIInterfaceOrientationIsLandscape(interfaceOrientation);
}

检查这两个函数,还有检查info.plist的Supported interface orientations的项目是否添加了相应的支持。我也相应检查了这几项,发现一切都正常。最后还是纠结了很久才发现问题。

1.我在项目启动的时候加入了GameCenter的鉴权,如果用户GameCenter可用,并且没有登录,首先会弹出一个GameCenter的登陆的Controller,这个是系统弹出的。

2.由于我的项目是横屏的,但是这个GameCenter弹出是以竖屏方式弹出的,我的项目里面只是提供了横屏的支持,这个时候就会崩溃。

做了多方面的改进,发现两个解决办法

1.在delegate中加入


- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)window
{
    return UIInterfaceOrientationMaskAll;
}

2. gameCenter的鉴权方式


if([GKLocalPlayer localPlayer].authenticated == NO)
        {
            [[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
             {
                 if (error == nil)
                 {
                 }
             }];

authenticateWithCompletionHandler这个方法已经被标注位__OSX_AVAILABLE_BUT_DEPRECATED。


改成:

[GKLocalPlayer localPlayer].authenticateHandler =
            ^(UIViewController *viewController, NSError *error)
            {
                if (error == nil)
                {
                }
            };


上面这两种方法只需要有一种就可以解决这个问题,ios6.0的模拟器,6.1的sdk的出现的问题。真机没有那么多版本的机器,也没能在真机上测试下。希望能遇到这个问题的同学们一个错误查找的方向

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值