Frage

I want to display localPlayer friends leaderboard in my app. I know I can get friends only scores from gamecenter but how do I get their display names? I know I can use loadPlayersForIdentifiers but do I have to make two calls? One to get all their friends names and one to get the leaderboards and them match them up? This seems somewhat inefficient?

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);
            }
        }
    }];
}
War es hilfreich?

Lösung

According to (under listing 4-12):

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

You have to use GKScore playerID property to get players' aliases after loading a scope of scores from a leaderboard. This is the only way to properly display a custom leaderboard. You can lazy load the aliases to a UITableView.

How to do it is described in listing 3-5 of the following doc:

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top