Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sometimes the Game Center authentication handler is never called

In our iOS game, we're using Game Center to identify players and sync their data across devices using our own servers. Because Game Center identifies players, we need to know if they're authenticated, or if they've changed authentication, etc. We have a title screen that displays "Initializing Game Center..." until the authentication call returns, and only once we know who they're authenticated as (if anyone) do we go into the game.

However, a very small amount of the time (in fact, I can't reproduce it myself), the authentication handler is never called, ever. Not even after minutes of waiting. The Game Center welcome banner never displays either, so it's not that just our handler is never called, but there really is no authentication status, it seems.

So far we've implemented a 30-second timeout where if we don't hear anything from Game Center, we assume the authentication status hasn't changed, and we use your saved data. That 30 second timeout is not ideal, so I'm wondering if there is any rhyme or reason to when GC does not respond.

Here is the code that is called from our App Delegate's application: didFinishLaunchingWithOptions: method:

PlayerModel *playerModel = [PlayerModel sharedPlayerModel];
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if ([localPlayer respondsToSelector:@selector(setAuthenticateHandler:)])
{
    localPlayer.authenticateHandler = ^(UIViewController *gkViewController, NSError *error)
    {
        if (localPlayer.authenticated)
        {
            [playerModel loadFromGameCenter];
            playerModel.hasGCStatus = TRUE;
            [playerModel sync];
        }
        else if (gkViewController)
        {
            [viewController presentViewController:gkViewController animated:TRUE completion:nil];
        }
        else
        {
            NSLog(@"Could not authenticate with Game Center");
            [playerModel unloadFromGameCenter];
            playerModel.hasGCStatus = TRUE;
            [playerModel sync];
        }
    };
}
else
{
    [localPlayer authenticateWithCompletionHandler:^(NSError *error) {
        if (localPlayer.authenticated)
        {
            [playerModel loadFromGameCenter];
            playerModel.hasGCStatus = TRUE;
            [playerModel sync];
        }
        else
        {
            NSLog(@"Could not authenticate with Game Center");
            [playerModel unloadFromGameCenter];
            playerModel.hasGCStatus = TRUE;
            [playerModel sync];
        }
    }];
}
like image 514
Rudd Zwolinski Avatar asked Oct 22 '22 02:10

Rudd Zwolinski


1 Answers

I had this experience during testing on one of our games on the sandbox server, there really was no notification or authentication handler call sometimes, then it would just work a half hour later.

We summised that it was due to Apple's server end as we never encountered this problem outside of the Game Center sandbox.

Sorry that the explanation is a little vague and there's nothing concrete that you can do. But it's not your code. It's on the end that you cannot control.

like image 69
David Wong Avatar answered Oct 27 '22 11:10

David Wong