Hot fix of Orientation Problem on iOS 6

Added by Zhe Wang 8 months ago

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

Added by Ben Ward 8 months ago

Thanks for the heads up Walzer.

Added by John G 8 months ago

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

Added by Herman Jakobi 8 months ago

- (NSUInteger) supportedInterfaceOrientations will only be called when the App has a deployment version of iOS6 !

Even when running on iOS6 device or compiled with iOS6 SDK (of course that must be done anyway).

Setting a deployment target of i.e. iOS4.3 will use the deprecated method.

Added by ho ho 8 months ago

My Game is compiled with ios 5.
Then I don't need those two hot fixes...?

Added by nikhil dhamsaniya 8 months ago

[window setRootViewController:viewController]; is backward completable up to ios 4.0 :)