向ios7的游戏中心报告得分

时间:2013-10-16 03:12:44

标签: ios7 game-center

根据https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html

使用

报告ios7中游戏中心的得分
[GKLeaderboard reportScores:scores withCompletionHandler:^(NSError *error) {
//Do something interesting here.
}];

但是,我在GKLeaderboard中找不到对此方法的任何引用。

此方法不存在: https://developer.apple.com/library/ios/documentation/GameKit/Reference/GKLeaderboard_Ref/Reference/Reference.html

GKLeaderboard.h也不包含reportScores方法。

以前使用GKScore的reportScoreWithCompletionHandler方法报告得分的方式已被弃用,因此我不愿意使用它。

有谁知道在ios7中向游戏中心报告得分的正确方法是什么?

1 个答案:

答案 0 :(得分:15)

我可以确认reportScores:withCompletionHandler:方法确实有效;我在我的一个应用程序中使用它。它位于头文件GKScore.h中。这就是我使用它的方式:

- (void) reportHighScore:(NSInteger) highScore {
    if ([GKLocalPlayer localPlayer].isAuthenticated) {
        GKScore* score = [[GKScore alloc] initWithLeaderboardIdentifier:MY_LEADERBOARD_ID];
        score.value = highScore;
        [GKScore reportScores:@[score] withCompletionHandler:^(NSError *error) {
            if (error) {
                // handle error
            }
        }];
    }
}
相关问题