Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Game Center. Get real name

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"
    }

 }
like image 780
Sinba Avatar asked Mar 13 '13 12:03

Sinba


People also ask

Does Apple Game Center give you a random name?

On your iPhone, iPad, or iPod touch Tap the Nickname field to enter a name that your friends will see when you play games together. If you can't think of a name, you can choose one of the randomly generated suggestions.

How do I find my Game Center username?

Open your Settings Application then locate "Game Center" and tap on this. Your Game Center ID is your Apple ID. After iOS 10 there is no Game Center app, so all Game Center settings must be managed in here. For iOS 10 you can see your Game Center username in the Game Center application.

Is Game Center tied to Apple ID?

Game Center uses the Apple ID that's linked to your iPhone or iPad by default. Since Game Center accounts are tied to Apple accounts, you may have been under the notion that you cannot use a different account unless you completely sign out of your device.


2 Answers

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.

like image 141
veducm Avatar answered Oct 23 '22 22:10

veducm


Use [GKLocalPlayer localPlayer].

NSString *alias = [GKLocalPlayer localPlayer].alias
NSString *name = [GKLocalPlayer localPlayer].displayName
like image 33
dragosaur Avatar answered Oct 23 '22 22:10

dragosaur