4

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

Ryan Maloney
  • 996
  • 11
  • 28
  • 1
    Show details of the crash. Log output, crash report, etc – Ben Trengrove Sep 27 '12 at 01:21
  • I edited my post to include the unhandled exception. Is that what you needed? – Ryan Maloney Sep 27 '12 at 23:29
  • I found this:http://stackoverflow.com/questions/12427979/gamecenter-authentication-in-landscape-only-app-throws-uiapplicationinvalidinter . It's not crashing now, but it's launching the GC Modal View in Portrait, not Landscape. – Ryan Maloney Sep 28 '12 at 00:04
  • i [reported this as a bug to Apple](http://bugreport.apple.com/) (#12485648) - if you do the same, they may act more quickly to provide a landscape oriented login to game center – bshirley Oct 12 '12 at 03:49
  • Thanks bshirley, but I'm pretty sure Apple is well aware of the problem by now. It is part of the iOS 6 Release Notes as a known bug. – Ryan Maloney Oct 16 '12 at 21:02

2 Answers2

5

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

Apps should provide the delegate method application:supportedIntefaceOrientationsForWindow and ensure that portrait is one of the returned mask values.

I added below code to fix this crash.

- (NSUInteger)application:(UIApplication*)application supportedInterfaceOrientationsForWindow:(UIWindow*)window
{
    return UIInterfaceOrientationMaskAllButUpsideDown;
}
i.Posei
  • 108
  • 1
  • 7
  • 1
    That fixed my crash, but now the GC Auth view appears in Portrait, and not Landscape like the rest of my app. Do you know how to force it into Landscape? – Ryan Maloney Sep 28 '12 at 18:59
  • 1
    It ONLY comes in portrait. It was crashing because your app is only in landscape. The code above means landscape OR portrait (but not upside down), so it displayed in portrait. This will (no doubt) cause the quirk in your app that it undesirably rotates. Try setting a variable any returning something else when the user is authenticated. Enter a bug in Apple's system that landscape is not supported. – bshirley Oct 12 '12 at 00:29
0

Had similar issue, I was testing the isAuthenticated and authenticateHandler from within viewDidLoad, kept crashing when trying to present the Game Center View whilst in the middle loading the current view. I moved this test into viewDidAppear

  • (void)viewDidAppear:(BOOL)animated{

it works fine now...

Also for ios 6, Game Center will only prompt a non authenticated user once, if they decline to sign-in, it will disable Game Center for that app, the user will then have go into Game Center to log in.

Jamie West
  • 86
  • 2