I am building a game in Cocos2d-iPhone, and while I was updating to iOS 6, I noticed that Apple changed the way Game Center authentication is done, using authenticateHandler
instead of authenticateWithCompletionHandler
.
I added the new authentication method, but the game now crashes if a player is not already logged in to Game Center. There is no problem authenticating if a user is already logged in.
Here is my code:
if(SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"6.0"))
{
GKLocalPlayer *localPlayer = [GKLocalPlayer localPlayer];
localPlayer.authenticateHandler = ^(UIViewController *viewController, NSError *error)
{
if (viewController != nil)
{
AppController *appDelegate = (AppController*)[UIApplication sharedApplication].delegate;
[delegate.viewController presentViewController:viewController animated:YES completion:nil];
}
else if (localPlayer.isAuthenticated)
{
NSLog(@"Player authenticated");
}
else
{
NSLog(@"Player authentication failed");
}
};
}
It seems like it's crashing when trying to present the Game Center viewController, even though I use the exact same code to present the GKTurnBasedMatchmakerViewController
with no issues.
Any help would be much appreciated.
EDIT: Here is the exception getting thrown on crash:
Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES