2012-09-25 14 views
7

Minimal Deployment TargetをiOS 5.0に設定したアプリでiOS6の機能をサポートするにはどうすればよいですか?iOS 5アプリのiOS 6機能の条件付きサポート

たとえば、ユーザーがiOS 5をお持ちの場合はUIActionSheetと表示されます。ユーザーがiOS 6をお持ちの場合は、iOS 6に別のUIActionSheetが表示されますか?これどうやってやるの? 私はXcode 4.5を持っていて、iOS 5でアプリを稼働させたいと思っています。

答えて

19

iOSのバージョンではなく利用可能なメソッド/機能を検出してから、方法が利用可能であると仮定してください。

Apple documentationを参照してください。例えば

、iOSの5で、我々はこのようなものだろうモーダルビューコントローラ表示する:iOSの6で

[self presentModalViewController:viewController animated:YES]; 

を、UIViewControllerpresentModalViewController:animated:方法が推奨されていません、あなたは、iOS 6でpresentViewController:animated:completion:を使用する必要があり、何をいつ使うべきかあなたはどのように知っていますか?

あなたはiOSのバージョンを検出することができ、前者または後者を使用するかどうかを指定するif文を使用できますが、これは壊れやすいため間違いを犯します。将来新しいOSでこれを行う新しい方法があります。

これを処理するための正しい方法は次のとおりです。

if([self respondsToSelector:@selector(presentViewController:animated:completion:)]) 
    [self presentViewController:viewController animated:YES completion:^{/* done */}]; 
else 
    [self presentModalViewController:viewController animated:YES]; 

あなたも、あなたがより厳しいことなど何かをするべきであると主張することができます:

if([self respondsToSelector:@selector(presentViewController:animated:completion:)]) 
    [self presentViewController:viewController animated:YES completion:^{/* done */}]; 
else if([self respondsToSelector:@selector(presentViewController:animated:)]) 
    [self presentModalViewController:viewController animated:YES]; 
else 
    NSLog(@"Oooops, what system is this !!! - should never see this !"); 

私はあなたのUIActionSheet例について不明なんです、私が知っている限り、これはiOS 5と6で同じです。UIActivityViewControllerを共有していると思いますが、iOS 5を使用している場合はUIActionSheetにフォールバックすることができます。利用可能、それを行う方法0。

+1

ありがとうございました!圧倒的に素晴らしい答えです! –

+0

about.me賛辞の喜びと感謝 – Daniel

+0

プロジェクト設定でフレームワークにリンクすることができます。その場合、フレームワークがすべてのバージョンに存在しない場合があります。例えば、includeをオプションに設定するだけですむしろ必要である。 ----質問が削除されました....質問/コメント。 – Daniel

関連する問題