iOS 6 游戏中心身份验证崩溃

2023-12-01

我正在 Cocos2d-iPhone 中构建游戏,当我更新到 iOS 6 时,我注意到 Apple 改变了 Game Center 身份验证的完成方式,使用authenticateHandler代替authenticateWithCompletionHandler.

我添加了新的身份验证方法,但如果玩家尚未登录 Game Center,游戏现在会崩溃。如果用户已经登录,则身份验证没有问题。

这是我的代码:

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");
        }
    };
}

尝试呈现游戏中心视图控制器时似乎崩溃了,即使我使用完全相同的代码来呈现GKTurnBasedMatchmakerViewController没有任何问题。

任何帮助将非常感激。

编辑: 这是崩溃时抛出的异常:

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


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

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

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

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS 6 游戏中心身份验证崩溃 的相关文章

随机推荐