Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I find out the GameCenter user name that's actively logged in?

I'd like my iphone app to pre-populate some fields once a user has logged into gamecenter. Specifically, the username!

I have full logging in working - as well as a leaderboard and acheivements all working - I just can't seem to find out how to access the users name property anywhere.

Any advice / help would be greatly appreciated.

Thanks, Kolya PS - This is my first question. Please be nice :-)

Here is the code I'm trying:

if ([GameCenterManager isGameCenterAvailable]) {

    self.gameCenterManager = [[[GameCenterManager alloc] init] autorelease];
    [self.gameCenterManager setDelegate:self];
    [self.gameCenterManager authenticateLocalUser];

    NSLog(@"User alias: %@",[[GKLocalPlayer localPlayer]alias]);

But the NSLog outputs "User alias: (null)"?

like image 934
Kolya Miller Avatar asked Jan 20 '23 19:01

Kolya Miller


1 Answers

As the local player is the subclass of GKPlayer, you could use this:

[[GKLocalPlayer localPlayer]alias]

Oh.. you have not authenticate the user... It is the first step..

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

I think you can just replace the 3 lines of codes with the code above.. Should work..

like image 65
xuanweng Avatar answered Jan 30 '23 07:01

xuanweng