Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 279
x0b Avatar asked Nov 09 '10 10:11

x0b


1 Answers

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...

like image 150
xuanweng Avatar answered Oct 05 '22 20:10

xuanweng