1

我想localPlayer在我的应用中显示好友排行榜。我知道我只能从游戏中心获得朋友的分数,但我如何获得他们的显示名称?我知道我可以使用loadPlayersForIdentifiers,但我必须打两个电话吗?一个得到他们所有朋友的名字,一个得到排行榜,他们匹配他们?这似乎有些低效?

GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init];
if (leaderboardRequest != nil)
{
    leaderboardRequest.playerScope = GKLeaderboardPlayerScopeFriendsOnly;
    leaderboardRequest.timeScope = GKLeaderboardTimeScopeAllTime;
    leaderboardRequest.category = @"HighScore";
    leaderboardRequest.range = NSMakeRange(1,100);
    [leaderboardRequest loadScoresWithCompletionHandler: ^(NSArray *scores, NSError *error) {
        if (error != nil)
        {
            // Handle the error.
        }
        if (scores != nil)
        {
            GKScore* myScore = leaderboardRequest.localPlayerScore;

            NSLog(@"Me: %@: %d",myScore.playerID, (int)myScore.value);

            // Process the score information - here I would filter
            for (GKScore* score in scores) 
            {
                NSLog(@"%@: %d",score.playerID, (int)score.value);
            }
        }
    }];
}
4

1 回答 1

0

根据(清单 4-12 下):

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/LeaderBoards/LeaderBoards.html#//apple_ref/doc/uid/TP40008304-CH6-SW4

GKScore playerID从排行榜加载分数范围后,您必须使用属性来获取玩家的别名。这是正确显示自定义排行榜的唯一方法。您可以将别名延迟加载到UITableView.

如何做到这一点在以下文档的清单 3-5 中进行了描述:

https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/GameKit_Guide/Users/Users.html#//apple_ref/doc/uid/TP40008304-CH8-SW20

于 2013-10-16T00:27:14.000 回答