我正在Cocos2d-iPhone中构建一个游戏,当我更新到iOS 6时,我注意到苹果改变了游戏中心认证的方式,使用authenticateHandler而不是authenticateWithCompletionHandler。
我添加了新的身份验证方法,但是如果玩家还没有登录到游戏中心,游戏现在就会崩溃。如果用户已经登录,进行身份验证是没有问题的。
下面是我的代码:
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
AppController *appDelegate = (AppController*)[UIApplication sharedApplication].delegate;
[delegate.viewController presentViewController:viewController animated:YES completion:nil];
}
else if (localPlayer.isAuthenticated)
{
NSLog(@"Player authenticated");
}
else
{
NSLog(@"Player authentication failed");
}
};
}在尝试呈现游戏中心viewController时,它似乎崩溃了,即使我使用完全相同的代码来呈现GKTurnBasedMatchmakerViewController没有任何问题。
任何帮助都将不胜感激。
编辑:下面是在崩溃时抛出的异常:
Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES
发布于 2012-09-28 19:17:48
在这里你可以找到关于你崩溃的有用信息,我认为这是潜在的原因。https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html
应用程序应该提供委托方法application:supportedIntefaceOrientationsForWindow,并确保肖像是返回的掩码值之一。
我添加了下面的代码来修复这个崩溃。
- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
return UIInterfaceOrientationMaskAllButUpsideDown;
}发布于 2012-09-27 18:30:28
有类似的问题,我在viewDidLoad中测试isAuthenticated和authenticateHandler,当在中间加载当前视图时,当试图呈现游戏中心视图时,一直崩溃。我将这个测试移到了viewDidAppear中。
它现在工作得很好。
同样对于ios 6,游戏中心将只提示未认证的用户一次,如果他们拒绝登录,它将禁用该应用程序的游戏中心,然后用户将进入游戏中心登录。
https://stackoverflow.com/questions/12612643
复制相似问题