You can check the systemVersion UIDevice property as follows:
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 5.0f) {
But personally, I donβt like this method, because I donβt like parsing the string returned from systemVersion and comparing it like this.
The best way is to verify that any class / method you want to use exists. For instance:
If you want to use TWRequest from the Twitter framework:
Class twRequestClass = NSClassFromString(@"TWRequest"); if (twRequestClass != nil) {
Or if you want to use startMonitoringForRegion: from the CLLocationManager that was included in iOS 5.0:
CLLocationManager *locationManager = [[CLLocationManager alloc] init]; ... if ([locationManager respondsToSelector:@selector(startMonitoringForRegion:)]) {
In general, it is better to do such checks than to look at the version of the system.
source share