Error iOS 6 Game Center authentication

I am creating a game on Cocos2d-iPhone, and while I was upgrading to iOS 6, I noticed that Apple had changed the way Game Center was authenticateHandler using authenticateHandler instead of authenticateWithCompletionHandler .

I have added a new authentication method, but now the game ends if the player has not yet entered the Game Center. There is no authentication problem if the 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 to crash when trying to present the Control Center viewController, although I use the same code to present the GKTurnBasedMatchmakerViewController without a problem.

Any help would be greatly appreciated.

EDIT: Here is the exception caused by the failure:

Uncaught Exception UIApplicationInvalidInterfaceOrientation: Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES

+3
source share
2 answers

Here you can find useful information about your failure, I think this is the main reason. https://developer.apple.com/library/ios/#releasenotes/General/RN-iOSSDK-6_0/_index.html

Applications should provide a delegate method application: supportedIntefaceOrientationsForWindow and ensure that the portrait is one of the return values ​​of the mask.

I have added the code below to fix this failure.

 - (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window { return UIInterfaceOrientationMaskAllButUpsideDown; } 
+5
source

Had a similar problem, I tested isAuthenticated and authenticateHandler from inside viewDidLoad, continued to crash when trying to present a Game Center view, while in the middle I loaded the current view. I transferred this test to viewDidAppear

  • (voids) viewDidAppear: (BOOL) animated {

Now it works fine ...

In addition, for ios 6, the Game Center will ask the user without authentication once, if he refuses to log in, he will disable the Game Center for this application, then the user will enter the Game Center to enter.

0
source

Source: https://habr.com/ru/post/926273/


All Articles