I'd like to be able to tell at compile time if I'm compiling for iPhone SDK 2.x or 3.x, so I can leave out some bits (e.g. MapKit, Gam开发者_运维技巧eKit) if need be. Currently I'm doing this using a custom #define. I'm wondering if there is a way of detecting this automatically from the active SDK? I know about TARGET_OS_IPHONE and TARGET_IPHONE_SIMULATOR, and TargetConditionals.h, but could not find anything related to the active SDK.
Have a look at Availability.h (and AvailabilityInternal.h). There's __IPHONE_OS_VERSION_MIN_REQUIRED
defined there as well as constants for SDK version.
Martijn is correct: __IPHONE_OS_VERSION_MIN_REQUIRED is the deployment target. The current base SDK is __IPHONE_OS_VERSION_MAX_REQUIRED.
If you're trying to use this to work out which features are available on the device that your code is running on though, you can't do this using compile-time macros, you need to use runtime feature detection.
If you want to check if a specific (or later) version of the SDK is being used, there are some defines you can check for.
For example, if you had some code that you only wanted to compile in only if the iOS 6.0 or later SDK was being used, you could use this:
#ifdef __IPHONE_6_0
// Some iOS 6 code
#endif
精彩评论