Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Built-in preprocessor token to detect iPhone platform

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!

like image 220
Richard Viney Avatar asked Jul 05 '09 06:07

Richard Viney


2 Answers

From this site we find that you need TARGET_OS_IPHONE

#if TARGET_OS_IPHONE
//Do iPhone stuff
#else
//Do Mac stuff
#endif
like image 108
Louis Gerbarg Avatar answered Sep 19 '22 12:09

Louis Gerbarg


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
like image 41
Nathan de Vries Avatar answered Sep 20 '22 12:09

Nathan de Vries