How can I check and conditionally only compile / run code if iOS5 is available ?
You can either check the systemVersion property of UIDevice like so:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0f) {
    // Do something
}
But personally I don't like that method as I don't like the parsing of the string returned from systemVersion and the comparison done like that.
The best way is to check that whatever class / method it is that you want to use, exists. For example:
If you want to use TWRequest from the Twitter framework:
Class twRequestClass = NSClassFromString(@"TWRequest");
if (twRequestClass != nil) {
    // The class exists, so we can use it
} else {
    // The class doesn't exist
}
Or if you want to use startMonitoringForRegion: from CLLocationManager which was brought in in iOS 5.0:
CLLocationManager *locationManager = [[CLLocationManager alloc] init];
...
if ([locationManager respondsToSelector:@selector(startMonitoringForRegion:)]) {
    // Yep, it responds
} else {
    // Nope, doesn't respond
}
In general it's better to do checks like that than to look at the system version.
Try out this code:
if([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0)
{
     //Do stuff for iOS 5.0
}
Hope this helps you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With