How to target a specific iPhone version?
Solution 1:
You can use this #define to change what you build for each SDK...
#if __IPHONE_OS_VERSION_MIN_REQUIRED > __IPHONE_2_2
// iPhone 3.0 code here
#endif
And do this at run-time to run code for 3.0 and above:
float version = [[[UIDevice currentDevice] systemVersion] floatValue];
if (version >= 3.0)
{
// iPhone 3.0 code here
}
Solution 2:
I'd be careful with the floatValue return result:
[[[UIDevice currentDevice] systemVersion] floatValue]
As with any floats, it may not be exactly what you expect. When running the above on my system, confused why my conditional statement wasn't executing, I noticed the value returned was:
3.20000005
Recommend the solutions here instead: How to check iOS version?
Excerpt:
NSComparisonResult order = [[UIDevice currentDevice].systemVersion compare: @"3.1.3" options: NSNumericSearch];
if (order == NSOrderedSame || order == NSOrderedDescending) {
// OS version >= 3.1.3
} else {
// OS version < 3.1.3
}