6

I want to know real name of local player, but GKLocalPlayer's displayName return "Me", not real name.

Code what I use:

 void (^completitionHandler)(NSArray *, NSError *) = ^(NSArray *players, NSError *error) { 

    for (GKPlayer *p in players) {
      NSString *alies = p.alies;
      NSString *name = p.displayName;
      NSLog(@"name = %@",name);   //not real name, just "Me"
    }

 }
Sinba
  • 314
  • 3
  • 12
  • Please update the question with a solution or mark the correct answer from the given ones as the accepted one. Thanks! – veducm Jan 22 '14 at 11:51

3 Answers3

4

Not sure displayName can be used to retrieve the local user full name. From Apple's documentation:

Player Objects Provide Details About Players

When your game needs details for a particular player, it retrieves those details by making a query to Game Center. You retrieve information for a player using that player’s player identifier. Game Kit returns those details to your game in a GKPlayer object.

  • displayName:

    A user-readable string you can display for this player in your own user interface. For example, in a network match, you might show the display names for each player in the match so that everyone knows who they are playing against.

    The display name for a player depends on whether the player is a friend of the local player authenticated on the device. If the player is a friend of the local player, then the display name is the actual name of the player. If the player is not a friend, then the display name is the player’s alias.

It is meant to retrieve the name of other players. Then, if you are asking for the displayName of the local player, it makes sense that it returns "Me", since you are the current user of this device. I guess this has to do with the privacy policy.

Possible Workaround:

Maybe, you could get the local user ID and use it to try to retrieve the real name from the list of players for that ID. But I do not know if it would be taken as you are a friend of yourself or not.

veducm
  • 5,933
  • 2
  • 34
  • 40
3

Use [GKLocalPlayer localPlayer].

NSString *alias = [GKLocalPlayer localPlayer].alias
NSString *name = [GKLocalPlayer localPlayer].displayName
Elliott
  • 4,598
  • 1
  • 24
  • 39
dragosaur
  • 818
  • 1
  • 8
  • 10
2

You Can Get The nick Name or Alias But After Making Sure Authentication is done .. other wise it will bring you nil,

use this code after finishing authentication

NSString *userID = [[NSString alloc] initWithString:[GKLocalPlayer localPlayer].alias];
NSLog(@"%@", userID);
Ahmed El-Bermawy
  • 2,173
  • 1
  • 14
  • 16