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