开发者

Gaming Center iphone-sdk, how to get current player's nickname?

When my app start it should promt user to log into gaming center so that I can retrieve his nickname and then use it later to display his name, I have the following code which somehow 开发者_开发问答worked once:

- (void) authenticateLocalPlayer
{
    GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    [localPlayer authenticateWithCompletionHandler:^(NSError *error) {
        if (localPlayer.isAuthenticated)
        {
            // Perform additional tasks for the authenticated player.
        }
    }];

}

It showed a alert view with and some buttons, but it doesn't work. Help, maybe there's an easier way to retrieve current player's nickname. Thanks!!


Getting a player's alias requires authentication with Game Center. Once you have authentication, all you have to do is get your GKPlayer instance by doing this:

GKLocalPlayer *lp = [GKLocalPlayer localPlayer];

and then, just make sure authentication occurred and get your alias:

if (lp.authenticated) {
    return lp.alias;
    //Any other stuff you need to do with this local player's instance goes here.
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜