In an iPhone app I fetch the Game Center local player by the following code in GameCenterViewController.m:

- (void)fetchUser
{
    __weak GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
    localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) {
        if (viewController != nil) {
            [self presentViewController:viewController
                               animated:YES
                             completion:nil];

        } else if (localPlayer.isAuthenticated) {
            NSLog(@"%s: displayName=%@ playerID=%@", __PRETTY_FUNCTION__,
                  [localPlayer displayName],
                  [localPlayer playerID]);

            User *user     = [[User alloc] init];
            user.userId    = [localPlayer playerID];
            user.firstName = [localPlayer displayName];
            [user save];

            dispatch_async(dispatch_get_main_queue(), ^(void){
                [self performSegueWithIdentifier: @"replaceGameCenter" sender: self];
            });
        }

        NSLog(@"%s: error=%@", __PRETTY_FUNCTION__, error);
    };
}

The corresponding debugger output and the screenshot are below:

__37-[GameCenterViewController fetchUser]_block_invoke: displayName=Me playerID=G:216741811
__37-[GameCenterViewController fetchUser]_block_invoke: error=(null)

app screenshot

Why do I get "Me" and not "farber72" there?

有帮助吗?

解决方案

What you see in the title is probably player alias.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top