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"
}
}
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.
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.
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.
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.
Use [GKLocalPlayer localPlayer].
NSString *alias = [GKLocalPlayer localPlayer].alias
NSString *name = [GKLocalPlayer localPlayer].displayName
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With