【问题标题】:Reporting score to GameCenter in iOS 9 (xCode 7.1.1)在 iOS 9 (xCode 7.1.1) 中向 GameCenter 报告分数
【发布时间】:2015-12-07 21:24:36
【问题描述】:

所以我有一个完成的游戏,我只是在提交到 App Store 之前进行整理。

由于我完成了大部分编码,我已将 xCode 更新到 7.1.1,并将我的设备从 8.1 更新到 iOS 9.1。

我学到的第一件事是游戏中心中没有沙盒切换(这是我经常使用的,没有问题)

现在,当我运行应用程序时,使用此代码报告分数时:

-(void)reportScore{
    GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];
    this_score.value = gameScore;

    [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) {
        if (error != nil) {
            NSLog(@"%@", [error localizedDescription]);
        }
    }];
    NSLog(@"Reported to Game Center...");
}

我将此错误打印到控制台:

*** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A GKScore must specify a leaderboard.'
*** First throw call stack:
(0x184e60f48 0x199a13f80...  ...0x1000d9748... ...0x19a2628b8)
libc++abi.dylib: terminating with uncaught exception of type NSException

其中规定,GKScore 必须指定 leaderboard...

我很困惑,因为在我更新到 iOS 9 之前,它运行良好。

我一直在阅读一堆关于在 iOS 9 中合并沙盒的内容,但我并不完全了解。

据我所知,它已合并到真实帐户中,所有沙盒数据都已删除,并且在真实排行榜上进行了测试?我可能错了。就像我说的,我不是 100% 的。

我该如何解决这个问题?我不确定找到准确资源的正确术语......我已经疯狂地搜索了很长时间。

也许我需要在本地指定我的 LeaderboardIdentifier?

提前致谢。

更新

这比我想象的还要糟糕…… 现在,我在 App Store 中的所有应用程序在尝试打开/提交到 Game Center 时都会崩溃...?

自从reading this...之后我只是想测试它们...

是否有更简洁或更新的方法来实现 Game Center?

【问题讨论】:

    标签: ios exception game-center


    【解决方案1】:

    所以,我有一个解决方法......似乎正在工作。我将在接下来的几个小时(或几天)内进行相应的更新...

    我的预感是对的,如果我在方法中使用字符串指定LeaderboardIdentifier,它现在看起来像这样:

    //GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:_leaderboardIdentifier];
    GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"myGameLeaderboardID"];
    

    加上方便的NSLogs 我还包括在内,我的callmethod 看起来像这样:

    -(void) GameOver {
            .
            .
            .
        if(_gameCenterEnabled){
            NSLog(@"--Reporting Score to Game Center...");
            [self reportScore];
        }
    }
    
    -(void)reportScore{
        NSLog(@"--- Got to the method");
        GKScore *this_score = [[GKScore alloc] initWithLeaderboardIdentifier:@"Enemies_Located"];
        NSLog(@"---- Alloc GKScore done");
        this_score.value = gameScore;
        NSLog(@"----- Score assigned to GKScore");
    
        [GKScore reportScores:@[this_score] withCompletionHandler:^(NSError *error) {
            if (error != nil) {
                NSLog(@"%@", [error localizedDescription]);
            }
        }];
        NSLog(@"Reported to Game Center...");
    }
    

    这会导致以下控制台打印出来:

    2015-12-07 23:20:24.666 myGame[88.....48] Some InGame Ref: 15
    2015-12-07 23:20:24.704 myGame[88.....48] --Reporting Score to Game Center...
    2015-12-07 23:20:24.704 myGame[88.....48] --- Got to the method
    2015-12-07 23:20:24.705 myGame[88.....48] ---- Alloc GKScore done
    2015-12-07 23:20:24.705 myGame[88.....48] ----- Score assigned to GKScore
    2015-12-07 23:20:24.705 myGame[88.....48] Reported to Game Center...
    

    这绝不是解决此问题的官方方法,环顾论坛很多人现在都有,因此为什么我几天不回答这个问题......但它似乎正在工作为了我。如果您对此也有任何运气,或者您知道在 iOS 9 上实现此功能的更好方法,请告诉我。

    同时,我现在应该更新我所有的应用了 -_-

    【讨论】:

    • 我一直用于 Game Center 的方式将 leaderboardIdentifier 设置为本地 NSString 变量。因此,您的解决方法似乎使用了相同的概念。
    • 感谢您告诉我。我想这只会影响使用设备沙盒的人,让构建直接从 iTunesConnect 检索排行榜 ID,而不是在本地存储它:/
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-03
    • 2016-02-13
    • 1970-01-01
    • 1970-01-01
    • 2016-03-11
    • 1970-01-01
    相关资源
    最近更新 更多