4

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

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

任何帮助将非常感激。

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

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

4

2 回答 2

5

在这里您可以找到有关崩溃的有用信息,我认为这是根本原因。 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;
}
于 2012-09-28T11:17:47.917 回答
0

有类似的问题,我在 viewDidLoad 中测试 isAuthenticated 和 authenticateHandler,在中间加载当前视图时尝试呈现游戏中心视图时一直崩溃。我将此测试移至 viewDidAppear

  • (void)viewDidAppear:(BOOL)动画{

现在工作正常...

同样对于 ios 6,Game Center 只会提示未经身份验证的用户一次,如果他们拒绝登录,它将禁用该应用程序的 Game Center,然后用户将进入 Game Center 登录。

于 2012-09-27T10:30:27.920 回答