Fixing orientation in Cocos2d with iOS6 when GameCenter is enabled

Fixing device orientation for Cocos2d in iOS6

iOS6 has caused a ruckus for Cocos2d developers with games that are only in landscape mode that have Game Center enabled. Either this happens:

or this happens:

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

In a nutshell, the cause is because someone at Apple thought that the Game Center sign in screen should ONLY be available in portrait mode, so whenever GameCenter is prompted for the user, it crashes. If you search Apple’s developer forum, you’ll find this post as Apple’s suggested method of fixing the bug, and you’ll find that it doesn’t work with Cocos2d apps. In order to remedy the bug for cocos2d, you’ll need to do two things:

Allow portrait

Add this to your RootViewController

-(NSUInteger)supportedInterfaceOrientations { return UIInterfaceOrientationMaskAllButUpsideDown; } -(BOOL)shouldAutorotate { return [[UIDevice currentDevice] orientation] != UIInterfaceOrientationPortrait; }

Now it should work as expected:

Please enable JavaScript to view the comments powered by Disqus.

Disqus

Sharing is caring -