Thursday, 22 August 2013

Sometimes the Game Center authentication handler is never called

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];
}
}];
}

No comments:

Post a Comment