Question

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?

Was it helpful?

Solution

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top