GameCenter authentication in landscape-only app throws UIApplicationInvalidInterfaceOrientation
Solution 1
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.
Solution 2
Add to app delegate:
- (NSUInteger)application:(UIApplication *)application supportedInterfaceOrientationsForWindow:(UIWindow *)w {
return (NSUInteger)[application supportedInterfaceOrientationsForWindow:w] | (1<<UIInterfaceOrientationPortrait);
}
Solution 3
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.
Related videos on Youtube
Tertium
IOS, Android, Windows, WP7-10 Developer ...I had a dream. A black box. And myriads of macros swarmed there... they were green and slimy...
Updated on June 04, 2022Comments
-
Tertium almost 2 years
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.
-
Robotic Cat over 11 yearsI know you've found a workaround but this sounds like a bug and you should file it with Apple at bugreporter.apple.com
-
voyce over 11 yearsIt's a known issue detailed in the iOS 6.0 release notes under Game Center. This answer has the official workaround.
-
-
Tertium over 11 yearsHow exactly? Maybe you've forgot something? Summary? Or maybe you have many views (while I have only one as my app uses opengl view)?
-
jonathanpeppers over 11 yearsThis solution is a little better: stackoverflow.com/questions/12488838/…
-
Tertium over 11 yearsYou 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.
-
Sunkas over 11 yearsIt 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.
-
Tertium over 11 yearsYes, 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.
-
jamil ahmed over 11 yearsI had this problem but it worked fine in the simulator and only crashed on the hardware.
-
Tuhin Bhatt over 11 years@Tertium do you know a way how can i do the same in cocos2d game. Your help would be greatly appreciated.
-
Steph Thirion over 11 yearsThe solution @jonathanpeppers linked to (stackoverflow.com/questions/12488838/…) 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).