23
votes

Problem: If user is not logged into GameCenter account - GameCenter authentication view is launched in portrait mode (in ios 5 there were a modal dialog) asking to log in. But if I disable Portrait mode in xcode (Project Summary) or in supportedInterfaceOrientationsForWindow: (as my app supposed to run in landscape mode ONLY) I get:

Terminating app due to uncaught exception 'UIApplicationInvalidInterfaceOrientation', reason: 'Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES'

If I enable Portrait for ipad/iphone (and/or comment out supportedInterfaceOrientationsForWindow:) it works without crash, but I don't want portrait mode to be enabled.

5
I know you've found a workaround but this sounds like a bug and you should file it with Apple at bugreporter.apple.comRobotic Cat
It's a known issue detailed in the iOS 6.0 release notes under Game Center. This answer has the official workaround.voyce

5 Answers

27
votes

While writing this question and experimenting with code, it seems that I've found a solution: enable all orientations in project summary and remove application:supportedInterfaceOrientationsForWindow.

Add this code to ViewController:

- (NSUInteger)supportedInterfaceOrientations {
    return UIInterfaceOrientationMaskLandscape;
}

Now it works seamlessly.

6
votes

Add to app delegate:

- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {

return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);

}
1
votes

I have found that the problem is coming from the Game Center in my case. When in the simulator I do not have the Game Center initialized yet, it would like to pop up the login view, but in portrait mode. Once it is reaching this point it crashes if I disallowed portrait orientation. Strange bug in the OS as Game Center should take the allowed orientations only to be inline with our intention of landscape user interface.

I do not have the solution yet, but I will post if I find it.

0
votes

I had the same issue as you and I fixed it with a kinda, ugly work around, basically I have a global variable in my app that I use to choose what the valid interface orientations are. In the

    - (NSInteger)application : (UIApplication *)supportedInterfaceOrientationsForWindow:(UIWindow *)window{
          if(orientationIndicator == 1){
               return UIInterfaceOrientationMaskAllButUpsideDown;
          }
          else if(orientationIndicator == 2){
               return UIInterfaceOrientationMaskLandscape;
          }
     }

To declare the global variable put this in your appDelegate.m file :

          int orientationIndicator = 1;

To import the global variable use :

          extern int orientationIndicator;

Then you can change the value of orientation indicator and it will allow you to run in different interface types. So what I did was I start by making the orientationIndicator = 1. When you authenticate a player and initiate the login view controller set the orientation indicator to 2. When you dismiss the view (authenticate the player) then you can change it back to 1.

This is a slimy work around but it has worked for me.

Hope this helps!

0
votes

Catching the exception appears to work just fine for me:

@try {
    [rootNavigationController pushViewController:viewController animated:YES];
}
@catch (NSException *exception) {
    //somehow, catching this exception just allows the view controller to be shown?
}

In iOS 6.0, the exception is thrown, but if you catch it then the viewController will still be shown and GameCenter will behave as expected in landscape orientation.

An alternate solution is just to target iOS 6.1 and above, as Apple fixed the bug by that release.