xcode 是否有等效于 MAC_OS_X_VERSION_MIN_REQUIRED 的 iPhone?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/691904/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 18:31:07  来源:igfitidea点击:

Is there an iPhone equivalent of MAC_OS_X_VERSION_MIN_REQUIRED?

iphonecocoacocoa-touchxcode

提问by Daniel Dickison

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_REQUIREDpreprocessor macro which gets set to the value of the MACOSX_DEPLOYMENT_TARGETbuild setting by the compiler. Is there an equivalent on the iPhone?

我想根据我正在编译的 SDK 版本有条件地包含 iPhone 应用程序的代码。在 Mac OS X 上,有一个MAC_OS_X_VERSION_MIN_REQUIRED预处理器宏,它被MACOSX_DEPLOYMENT_TARGET编译器设置为构建设置的值。iPhone 上有类似的吗?

Update:

更新:

I've set IPHONE_DEPLOYMENT_TARGETto 3.0 in the build settings, but Xcode is passing -D__IPHONE_OS_VERSION_MIN_REQUIRED=20000and -mmacosx-version-min=10.5to GCC. Shouldn't the first one be 30000and 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:

更新 2:

Looks like I wasn't doing anything wrong. __IPHONE_OS_VERSION_MIN_REQUIREDand -miphoneos-version-minare 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 Simulator SDK 时才会出错。我认为这是模拟器 SDK 中的一个错误。

回答by Brent Royal-Gordon

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

有为操作系统的每个版本定义的预处理器宏。例如,如果__IPHONE_OS_3_0定义了,那么您是针对 3.0 SDK 构建的(或者可能稍后,我不确定)。

回答by Daniel Dickison

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_DEFINITIONSwith 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