Game Center custom leaderboard - Do I really need to make 2 calls to get a player's alias?
Asked Answered
P

1

6

I'm using game center to set up a custom leaderboard, when it comes to retrieving the data for my UITableView, I only get the playerID property for each entry, but not a much more useful alias property which I want to use to display who got each score.

I don't understand why Apple has done it like this, surely a score on a scoreboard is meaningless without the name of the player that got it?

Anyway, it seems the only way I can get the name of the player is to use the loadPlayersForIdentifiers:withCompletionHandler: method of the GKPlayer class. This seems like an unnecessary step - can anyone confirm whether this is what needs to be done just to get the player's alias?

Pippo answered 9/11, 2010 at 10:24 Comment(0)
P
4

Yes.. It only stores the id of the player.. So to load the actual alias, you would need to pass the playerid in and get the alias..

In case you not sure what is the actual codes:

if you want to get local player's alias is:

[[GKLocalPlayer localPlayer] alias];

other players:

    [GKPlayer loadPlayersForIdentifiers:playerIDsArray withCompletionHandler:^(NSArray *players, NSError *error)
   {
        if (error != nil)
        {
 // Handle the error.
        }
        if (players != nil)
        {

for(int i = 0; i<array_size; i++)            
[NameArray objectAtIndex:i]  = [[players objectAtIndex:i]alias];

        }
        }];

Hope it helps...

Pyrrhuloxia answered 25/11, 2010 at 4:15 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.