What's the difference between run-time, e.g., [[UIDevice currentDevice] systemVersion]
, and compile-time, e.g., __IPHONE_OS_VERSION_MIN_REQUIRED
checking? When should you one over the other?
Is__IPHONE_OS_VERSION_MIN_REQUIRED
just a variable set in Build Settings?
I've read the answers to How to target a specific iPhone version? and other related questions listed below.
But, I just noticed that __IPHONE_OS_VERSION_MIN_REQUIRED = 30200
when I build & run on iPhone (4.3.1) with Xcode 4. Why?
When you submit your code to Apple, do they compile a version of it for each version of the iPhone that exists, setting __IPHONE_OS_VERSION_MIN_REQUIRED
accordingly?
That way, you could inspect __IPHONE_OS_VERSION_MIN_REQUIRED
, and know what iOS version is running the code.
An example code below dumps the iOS version and checks whether the version is greater than or equal to 6.0. // Get the system version of iOS at runtime. NSString *versionString = [[UIDevice currentDevice] systemVersion]; // Convert the version string to a Version instance.
Nonetheless, you should be supporting iOS 6 by now and aspiring to support iOS 7 (if you aren't already). Overall, no matter what your scenario is, I highly recommend that you only support the latest two versions. Supporting the latest three iOS versions would only be necessary on the brink of a new iOS release.
__IPHONE_OS_VERSION_MIN_REQUIRED
is indeed just a build setting, which you can use in the preprocessor to modify code before compilation. No, Apple doesn't compile your code for each iPhone. They can't, since you don't give them the code. You can use compile time checking to determine, for example, if you need to compile code to emulate a new feature in older OS versions. However, you use runtime version checking to determine whether you should use the built in or emulated version of that feature.
For example, iAds were added in 4.0. You currently support 4.0 and later, but plan on adding support for 3.2 in the future. You make code to display other ads in older versions, using runtime checking to determine whether you should use iAds or other, but you don't want it to be in any releases until the rest of the application is ready for 3.2, since it will make your application larger. You use compile time checking so that the preprocessor leaves that code out of your releases. By using the minimum version macro, you can easily add the code to your release by changing the minimum version build setting.
Yes, __IPHONE_OS_VERSION_MIN_REQUIRED
is just the value for "iOS Deployment Target" under "Build Settings." Make sure the correct target, not the project, is selected.
And, __IPHONE_OS_VERSION_MAX_ALLOWED
corresponds to the "Base SDK" build setting.
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