当我的应用程序启动时,它应该促使用户登录游戏中心,以便我可以检索他的昵称,然后在以后使用它来显示他的名字, 我有以下代码以某种方式工作过一次:
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
// Perform additional tasks for the authenticated player.
}
}];
}
它显示了带有一些按钮的警报视图,但它不起作用。帮助,也许有一种更简单的方法来检索当前玩家的昵称。谢谢!
答案 0 :(得分:5)
获取玩家的别名需要使用Game Center进行身份验证。一旦进行了身份验证,您所要做的就是通过执行以下操作来获取GKPlayer实例:
GKLocalPlayer *lp = [GKLocalPlayer localPlayer];
然后,只需确保发生身份验证并获取别名:
if (lp.authenticated) {
return lp.alias;
//Any other stuff you need to do with this local player's instance goes here.
}