Daniel Dickison
Daniel Dickison

Reputation: 21882

Is there an iPhone equivalent of MAC_OS_X_VERSION_MIN_REQUIRED?

I would like to conditionally include code for an iPhone app depending on which version of the SDK I'm compiling against. On Mac OS X, there is the MAC_OS_X_VERSION_MIN_REQUIRED preprocessor macro which gets set to the value of the MACOSX_DEPLOYMENT_TARGET build setting by the compiler. Is there an equivalent on the iPhone?

Update:

I've set IPHONE_DEPLOYMENT_TARGET to 3.0 in the build settings, but Xcode is passing -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000 and -mmacosx-version-min=10.5 to GCC. Shouldn't the first one be 30000 and the second one be -miphoneos-version-min=3.0? What am I doing wrong?

Update 2:

Looks like I wasn't doing anything wrong. __IPHONE_OS_VERSION_MIN_REQUIRED and -miphoneos-version-min are both set correctly when building for a device -- it's only wrong when using the iPhone Simulator SDK. I think it's a bug in the simulator SDK.

Upvotes: 8

Views: 5471

Answers (3)

Becca Royal-Gordon
Becca Royal-Gordon

Reputation: 17871

There are preprocessor macros that are defined for each version of the OS. For example, if __IPHONE_OS_3_0 is defined, then you're building against the 3.0 SDK (or possibly later, I'm not certain).

Upvotes: 3

Daniel Dickison
Daniel Dickison

Reputation: 21882

For what it's worth, a decent work-around if such a macro does not exist, is to create 2 build targets, and in one of them add the build setting GCC_PREPROCESSOR_DEFINITIONS with a value like IPHONE_OS_3. Then in your code you can do:

#ifdef IPHONE_OS_3
    [foo thisMethodIsUnderNDA];
#else
    [foo oldSchoolMethod];
#endif

Upvotes: 2

Related Questions