【问题标题】:Errors while integrating GameCenter集成 GameCenter 时出错
【发布时间】:2014-06-05 11:03:23
【问题描述】:

所以,过去几天我一直在尝试将 GameCenter 添加到我的应用程序中,我发现一些教程似乎都不太好用,所以这是我在登录时想出的代码播放器打开应用

- (void)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    localPlayer.authenticateHandler =
    [localPlayer authenticate];
}


GKLocalPlayer.authenticationHandler = ^(UIViewController *loginVC,
                                      NSError *error)
{
    if ([GKLocalPlayer localPlayer].authenticated) {

        [self enableGameCenterForPlayer:[GKLocalPlayer localPlayer]];
    }
    else if (loginVC) {

        [self pauseGame];
        [self presentLoginVC:loginVC];
    }
    else {

        [self disableGameCenter];
    }
};

但是我遇到了 2 个错误,我不知道它们是什么意思,我很新,所以有些东西是有道理的,有些则没有,这就是其中之一,我想我看到了大约 9 或 10 种不同的做事方式这个。

觉得最好问问知道的人

这是错误的屏幕截图

谢谢你们,谢谢你们的帮助。

【问题讨论】:

    标签: ios xcode5 game-center


    【解决方案1】:

    文档中根本没有验证方法。 “要认证本地播放器,通过调用localPlayer类方法获取本地播放器的共享实例并设置它的authenticHandler”,所以应该删除第一行错误的行。第二个错误的行应该引用 localPlayer 并移到方法中:

    didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {
        GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    
        LocalPlayer.authenticationHandler = ^(UIViewController *loginVC,
                                              NSError *error)
        {
             ...
    

    【讨论】:

    • 抱歉,您的意思有点困惑?
    • 我编辑了我的答案以使其更清晰。看起来您可能还需要学习使用块。带块的变量不像方法那样添加,而是在方法中调用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-08
    相关资源
    最近更新 更多