GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation
Asked Answered
E

5

23

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.

Elodia answered 14/9, 2012 at 15:54 Comment(2)
I know you've found a workaround but this sounds like a bug and you should file it with Apple at bugreporter.apple.comMiguelinamiguelita
It's a known issue detailed in the iOS 6.0 release notes under Game Center. This answer has the official workaround.Burglary
E
27

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.

Elodia answered 14/9, 2012 at 15:54 Comment(7)
How exactly? Maybe you've forgot something? Summary? Or maybe you have many views (while I have only one as my app uses opengl view)?Elodia
This solution is a little better: #12489338Willi
You should read carefully. Both allow app portrait, but deny it for the main view. The only difference - in appdelegate code or in Project->Summary - is almost the same thing. Strange thing that Minna said that my workaround doesn't work, but I assume the root of an evil was in forgotten View::supportedInterfaceOrientations. In my simulator (xcode 4.5) both approaches do work.Elodia
It does work, but when I start my game standing in portrait position it not rotated correctly (the game thinks it's landscape), but rotating it either way makes it display properly. It is for landscape-left and landscape-right only.Bailey
I had this problem but it worked fine in the simulator and only crashed on the hardware.Nucleus
@Elodia do you know a way how can i do the same in cocos2d game. Your help would be greatly appreciated.Soandso
The solution @Willi linked to (#12489338) works better in my case. This solution fixed the problem in ios 6, but led to orientation oddities in my app under ios 5 (which I think are related with activating all the orientations in the project summary). The linked solution on the other hand seems to fix those problems, with the added advantage of having the right orientations displayed in the summary. (One last note: if implementing other solution, read my comment below it).Hector
V
6

Add to app delegate:

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

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

}
Viridian answered 15/12, 2012 at 6:27 Comment(0)
D
1

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.

Dree answered 30/9, 2012 at 16:9 Comment(1)
Yes, like it's written in the post title problem appears in "GameCenter authentication in landscape-only". It seems that GC just doesn't have landscape assets for auth screen for iphone in ios6, so I suspect you won't find a real solution - only workaround described here. That is why you have to allow app to launch in portrait mode when GC wants - but deny portrait in your main view - if you don't want portrait of course. By the way, there is no such a problem in ipad on ios6.Elodia
R
0

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!

Rapine answered 23/1, 2013 at 20:38 Comment(0)
E
0

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.

Eisen answered 16/2, 2014 at 18:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.