Game Center Authentication
While searching forums, I came across a lot of outdated code to enable game center in your iPhone app. Here is a solution that will allow you to authenticate your player in iOS 6:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
GKLocalPlayer* localPlayer = [GKLocalPlayer localPlayer]; __weak GKLocalPlayer *blockLocalPlayer = localPlayer; localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error) { [self setLastError:error]; if (blockLocalPlayer.authenticated) { _gameCenterFeaturesEnabled = TRUE; //boolean: keep track of authentication } else if(viewController) { [self presentViewController:viewController]; } else { _gameCenterFeaturesEnabled = FALSE; } }; |
It’s a good idea to create a game center helper singleton in order to deal with game center authentication, updates, challenges, and high scores. Also note, with changes to game center coming with iOS 7, authentication will become much more simpler.