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:
and then, just make sure authentication occurred and get your alias: