是否有相当于MAC_OS_X_VERSION_MIN_REQUIRED的iPhone?

时间:2021-08-07 06:58:53

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?

我想有条件地包含iPhone应用程序的代码,具体取决于我正在编译的SDK版本。在Mac OS X上,有MAC_OS_X_VERSION_MIN_REQUIRED预处理器宏,它由编译器设置为MACOSX_DEPLOYMENT_TARGET构建设置的值。 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?

我在构建设置中将IPHONE_DEPLOYMENT_TARGET设置为3.0,但Xcode将-D__IPHONE_OS_VERSION_MIN_REQUIRED = 20000和-mmacosx-version-min = 10.5传递给GCC。不应该第一个是30000而第二个是-miphoneos-version-min = 3.0?我究竟做错了什么?

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.

看起来我没有做错任何事。在为设备构建时,__ IPHONE_OS_VERSION_MIN_REQUIRED和-miphoneos-version-min都已正确设置 - 使用iPhone模拟器SDK时,这只是错误的。我认为这是模拟器SDK中的一个错误。

3 个解决方案

#2


3  

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).

为每个版本的OS定义了预处理器宏。例如,如果定义了__IPHONE_OS_3_0,那么您正在构建3.0 SDK(或者可能以后,我不确定)。

#3


2  

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:

对于它的价值,如果不存在这样一个宏,一个体面的解决方法是创建2个构建目标,并在其中一个中添加构建设置GCC_PREPROCESSOR_DEFINITIONS,其值为IPHONE_OS_3。然后在您的代码中,您可以:

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

#1


#2


3  

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).

为每个版本的OS定义了预处理器宏。例如,如果定义了__IPHONE_OS_3_0,那么您正在构建3.0 SDK(或者可能以后,我不确定)。

#3


2  

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:

对于它的价值,如果不存在这样一个宏,一个体面的解决方法是创建2个构建目标,并在其中一个中添加构建设置GCC_PREPROCESSOR_DEFINITIONS,其值为IPHONE_OS_3。然后在您的代码中,您可以:

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