我想知道本地播放器的真实姓名,但是GKLocalPlayer的displayName返回的是“我”,而不是真实姓名。
编码我使用的:
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"
}
}
最佳答案
不确定displayName可用于检索本地用户全名。来自 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.
它的目的是检索其他玩家的名字。然后,如果您要求本地播放器的显示名称,返回“Me”是有意义的,因为您是该设备的当前用户。我想这与隐私政策有关。
可能的解决方法:
或许,您可以获取本地用户 ID 并使用它来尝试从该 ID 的玩家列表中检索真实姓名。但是不知道会不会被当成你自己的 friend 。
关于ios - 游戏中心。获取真实姓名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15385236/