Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/38.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/eclipse/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 如何从GKLeaderboard加载好友的姓名?_Iphone_Ios_Objective C_Game Center_Gamekit - Fatal编程技术网

Iphone 如何从GKLeaderboard加载好友的姓名?

Iphone 如何从GKLeaderboard加载好友的姓名?,iphone,ios,objective-c,game-center,gamekit,Iphone,Ios,Objective C,Game Center,Gamekit,我想在我的应用程序中显示localPlayer好友排行榜。我知道我只能从gamecenter获得朋友的分数,但我如何获得他们的显示名?我知道我可以使用LoadPlayers作为标识符,但我必须打两个电话吗?一个是为了得到他们所有朋友的名字,一个是为了获得排行榜,然后让他们匹配他们?这似乎有点低效 GKLeaderboard *leaderboardRequest = [[GKLeaderboard alloc] init]; if (leaderboardRequest != nil) {

我想在我的应用程序中显示
localPlayer
好友排行榜。我知道我只能从gamecenter获得朋友的分数,但我如何获得他们的显示名?我知道我可以使用
LoadPlayers作为标识符
,但我必须打两个电话吗?一个是为了得到他们所有朋友的名字,一个是为了获得排行榜,然后让他们匹配他们?这似乎有点低效

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-12):

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

下面文档的清单3-5描述了如何执行此操作:


我在这里检查代码: