Skip to content

Instantly share code, notes, and snippets.

@sdabet
Created December 18, 2012 12:42
Show Gist options
  • Save sdabet/4327634 to your computer and use it in GitHub Desktop.
Save sdabet/4327634 to your computer and use it in GitHub Desktop.
Game Center authentication for both iOS 5 and iOS 6
- (void) authenticateLocalPlayer
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0")) {
// iOS 6
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error){
if (viewController != nil)
{
[navController_ presentViewController:viewController animated:false completion:nil];
}
else if (localPlayer.isAuthenticated)
{
// [self authenticatedPlayer: localPlayer];
}
else
{
// [self disableGameCenter];
}
};
} else {
// iOS 5
[localPlayer authenticateWithCompletionHandler:^(NSError *error) {
if (localPlayer.isAuthenticated)
{
// Perform additional tasks for the authenticated player.
}
else {
}
}];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment