Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You should always prefer detecting available methods/feature rather then iOS versions and then assuming a method is available.</p> <p>See <a href="http://developer.apple.com/library/mac/#documentation/developertools/conceptual/cross_development/Using/using.html" rel="noreferrer">Apple documentation</a>.</p> <p>For example, in iOS 5 to display a modal view controller we would do something like this:</p> <pre><code>[self presentModalViewController:viewController animated:YES]; </code></pre> <p>In iOS 6, the <code>presentModalViewController:animated:</code> method of <code>UIViewController</code> is Deprecated, you should use <code>presentViewController:animated:completion:</code> in iOS 6, but how do you know when to use what?</p> <p>You could detect iOS version and have an if statement dictate if you use the former or latter but, this is fragile, you'll make a mistake, maybe a newer OS in the future will have a new way to do this.</p> <p>The correct way to handle this is:</p> <pre><code>if([self respondsToSelector:@selector(presentViewController:animated:completion:)]) [self presentViewController:viewController animated:YES completion:^{/* done */}]; else [self presentModalViewController:viewController animated:YES]; </code></pre> <p>You could even argue that you should be more strict and do something like:</p> <pre><code>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 !"); </code></pre> <p>I'm unsure about your <code>UIActionSheet</code> example, as far as I'm aware this is the same on iOS 5 and 6. Maybe you are thinking of <code>UIActivityViewController</code> for sharing and you might like to fallback to a <code>UIActionSheet</code> if you're on iOS 5, so you might to check a class is available, see <a href="http://www.lukessandbox.com/2012/checking-for-objective-c-class-availability.html" rel="noreferrer">here</a> how to do so.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload