Hot fix of Orientation Problem on iOS 6
Since iOS updated some orientation relatived methods, cocos2d-x games with v2.0.2 and before can't be rendered to correct orientation.
I fixed it in this commit https://github.com/walzer/cocos2d-x/commit/70f1360ac2f0397ae8e32422a3be1d232bebd410
You can update your games simply with the codes below:
1. yougame/ios/AppController.mm. Change this line
1// Set RootViewController to window
2[window addSubview: viewController.view];
to
1// Set RootViewController to window
2if ( [[UIDevice currentDevice].systemVersion floatValue] < 6.0)
3{
4 // warning: addSubView doesn't work on iOS6
5 [window addSubview: viewController.view];
6}
7else
8{
9 // use this mehod on ios6
10 [window setRootViewController:viewController];
11}
2. In yourgame/ios/RootViewController.mm, we used this method to deal with auto rotation before ios6
1// Override to allow orientations other than the default portrait orientation.
2- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
3{
4 return UIInterfaceOrientationIsLandscape( interfaceOrientation );
5}
But this method is deprecated since iOS 6. Instead, we need to add 2 methods in RootViewController.mm
1// For ios6, use supportedInterfaceOrientations & shouldAutorotate instead of shouldAutorotateToInterfaceOrientation
2- (NSUInteger) supportedInterfaceOrientations{
3 return UIInterfaceOrientationMaskLandscape;
4}
5
6- (BOOL) shouldAutorotate {
7 return YES;
8}
Comments
Thanks for the heads up Walzer.
Does this also address the Game Center authentication crash in iOS6 ? I believe a portrait view MUST be supported for Game Center to not crash.
See here:
https://devforums.apple.com/message/731764#731764
http://www.cocos2d-iphone.org/forum/topic/36639
- (NSUInteger) supportedInterfaceOrientations will only be called when the App has a deployment version of iOS6 !
Setting a deployment target of i.e. iOS4.3 will use the deprecated method.
My Game is compiled with ios 5.
Then I don't need those two hot fixes...?
[window setRootViewController:viewController]; is backward completable up to ios 4.0