iOS 6游戏中心认证崩溃

Rya*_*ney 3 cocos2d-iphone game-center ios6

我正在使用Cocos2d-iPhone构建游戏,当我更新到iOS 6时,我注意到Apple改变了游戏中心身份验证的方式,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");
        }
    };
}
Run Code Online (Sandbox Code Playgroud)

在尝试呈现Game Center viewController时似乎崩溃了,即使我使用完全相同的代码来呈现GKTurnBasedMatchmakerViewController没有问题.

任何帮助将非常感激.

编辑:以下是崩溃引发的异常:

Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

小智 5

在这里,您可以找到有关崩溃的有用信息,我认为这是潜在的原因. https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

应用程序应提供委托方法应用程序:supportedIntefaceOrientationsForWindow并确保纵向是返回的掩码值之一.

我添加了以下代码来修复此崩溃.

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
Run Code Online (Sandbox Code Playgroud)