【问题标题】:Having issue with Game Center in iOS 6iOS 6 中的 Game Center 出现问题
【发布时间】:2012-09-26 21:40:59
【问题描述】:

我曾经使用此代码在游戏中心登录用户帐户:

[[GKLocalPlayer localPlayer] authenticateWithCompletionHandler:^(NSError *error)
     {
         if (error != nil)
         {
             NSLog(@"LOGIN");
         } else {
             NSLog(@"CANT LOGIN");
         }
     }];

此代码在 iOS 5.x 中运行良好,但在 iOS 6 中崩溃,如果您能帮助修复它,我将不胜感激。

谢谢

【问题讨论】:

  • 此方法在 iOS 6 中已弃用;改为设置 authenticateHandler 属性。 (不过,这可能无法解决您的崩溃问题。为此,您需要显示更多代码。)
  • 这是我登录GameCenter的代码!(上),你能给我一个示例代码吗?

标签: iphone cocoa-touch ios6 game-center


【解决方案1】:

需要检查iOS5还是6。iOS6更改了认证功能

iOS6

   localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
    {
        //Something
    }

iOS5

    [localPlayer authenticateWithCompletionHandler:^(NSError *error)
    {
        //Something
    }];

【讨论】:

    【解决方案2】:

    这适用于 iOS 6:

            GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
        localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
            if (viewController != nil) {
                [self presentViewController:viewController animated:YES completion:nil];
            } else if (localPlayer.isAuthenticated) {
                // do post-authentication work
            } else {
                // do unauthenticated work, such as error message, etc
            }
        };
    

    【讨论】:

      【解决方案3】:

      这里有Game Center Programming Guide

      这就是您必须在 iOS6 中验证用户的方式:

      - (void) authenticateLocalPlayer
      {
          GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
          localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
               if (viewController != nil)
               {
                   [self showAuthenticationDialogWhenReasonable: viewController
               }
               else if (localPlayer.isAuthenticated)
               {
                   [self authenticatedPlayer: localPlayer];
               }
               else
               {
                   [self disableGameCenter];
               }
           }];
      }
      

      您还应该检查this question,因为您的应用程序可能由于自动旋转问题和游戏中心而崩溃,而不是身份验证机制本身

      【讨论】:

      • 非常感谢 Lio,这段代码在 iOS 5 和 iOS 6 上一起工作吗?我的游戏在 iOS 5 上运行良好。我希望我的游戏在 iOS 5 和 iOS 6 上一起运行!请帮助我。我有不可抗力的工作。非常感谢。
      • 看到这个错误:1.3.3.img98.net/out.php/…
      • 这些错误是因为我粘贴的代码是示例代码,您实际上必须实现这些方法。回答你以前的方法,不,代码只适用于iOS6。我在 iOS6 中使用旧的 iOS5 代码,它仍然可以正常工作。您应该追踪崩溃并找出原因。我建议您查看我在回答中链接的那个问题。祝你好运
      • 这是从 Apple 的 Game Center 编程指南中复制/粘贴的:developer.apple.com/library/ios/#documentation/…,它本身包含一个错误。
      猜你喜欢
      • 1970-01-01
      • 2012-09-13
      • 1970-01-01
      • 1970-01-01
      • 2014-12-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 1970-01-01
      相关资源
      最近更新 更多