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)"?
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..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With