Cocos2d-iphone-2.0+iOS6のLandScape Crash問題に対応する

Cocos2d-iphone-2.0をiOS6で使う上で問題となったのが、

LandScapeオンリーのゲームで、GameCenterやカメラロールを開くとCrashするという案件がありました。↓みたいなの

 ‘UIApplicationInvalidInterfaceOrientation’, reason: ‘Supported orientations has no common orientation with the application, and shouldAutorotate is returning YES’

かといって、Portraitを対応してしまうと、回転時にレイアウトが大きく崩れてしまうという問題です。

これを、先日リリースした「パクパクマキシくん」はiOS4.3〜6まで対応、見た目はLandScapeオンリーとして動作しています。

この中で、なかば強引に回避していますので、もし同様の問題でお困りの方がいれば参考までに。

1.まず、Supported Interface OrientationsにPortraitを含める

f:id:maxigundan:20121113211944p:plain

2.AppDelegate.mからWrapする用のUINavigationControllerのサブクラスMyNaviController.m/.hを作成

f:id:maxigundan:20121113212325p:plain

f:id:maxigundan:20121113213123p:plain

 – (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation

{

    return UIInterfaceOrientationIsLandscape(interfaceOrientation);

}

をAppDelegate.mから移動。AppDelegate.mのものは消す。

これは従来通り。iOS5以前ではこっちが呼ばれるはず。

その下に以下のコード追加。

//iOS6 LandScapeCrash対策 ->

– (BOOL)shouldAutorotate

{

    return YES;

}

– (NSUInteger)supportedInterfaceOrientations

{

    return UIInterfaceOrientationMaskLandscapeLeft;

}

– (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation

{

    return UIInterfaceOrientationLandscapeLeft;

}

//iOS6 <- LandScapeCrash対策 

3.AppDelegate.mのnavContrllerをMyNaviControllerに変更

 #import “MyNaviController.h” のうえ、以下の場所をいじる

f:id:maxigundan:20121113213035p:plain

//    navController_ = [[UINavigationController alloc] initWithRootViewController:director_];

navController_ = [[MyNaviController alloc] initWithRootViewController:director_];

以上でなんとかCrashせずに済みました。

(StackOverflowかその辺りの書き込みを参考にした気がします)

ポイントは、「Supported Interface OrientationsにPortraitを含める」かな?

要するにGameCenterやPhotoAlbumは”Portrait”のサポートが必須なんだけど、それを「アプリ自体はPortrait対応してますよ」と宣言しつつ、ビューの表示/回転時に呼ばれる問い合わせメソッド(supportedInterfaceOrientations)ではUIInterfaceOrientationMaskLandscapeLeftしか対応していないと返事し、

これにより、問い合わせの来るゲーム画面内ではLandScapeLeftのみ、GameCenterではPortrait+LandScapeRight+Leftが表示できる、という理解で合ってますでしょうか。

「パクパクマキシくん」からGamecenterを起動するとわかると思いますが、

一瞬だけ回転アニメーションが見えてしまいます。

気になる人は気になるかもしれませんが、ほとんど気にならないレベルだと思わないでしょうか?

というわけで私はこのまま申請、無事リリースできました。

シェアする

  • このエントリーをはてなブックマークに追加

フォローする