开发者

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 mea开发者_JAVA百科ningless 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?


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜