Is there a single preprocessor token that can be used to detect any iPhone device or simulator at build time? I'm currently using:
#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
// This is an iPhone build
#endif
Is this the recommended approach or is there a better way? I'd prefer the macro to be built-in, i.e. defined by the compiler and not by an SDK header file I have to include.
I'm not concerned about distinguishing between iPhone OS versions right now, but if there's an Apple documentation page that details all the relevant macros and when they are and aren't defined then I'd appreciate a link to it as my searching has come up short thus far.
Thanks!
From this site we find that you need TARGET_OS_IPHONE
#if TARGET_OS_IPHONE
//Do iPhone stuff
#else
//Do Mac stuff
#endif
The file you're looking for is TargetConditionals.h
, which defines all the macros you're interested in. You'll find it in each version of the SDK, like the following path for the 2.2 SDK:
/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk/usr/include/TargetConditionals.h
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