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
Is there an iPhone equivalent of MAC_OS_X_VERSION_MIN_REQUIRED?
提问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_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?
我想根据我正在编译的 SDK 版本有条件地包含 iPhone 应用程序的代码。在 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:
更新 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 Simulator SDK 时才会出错。我认为这是模拟器 SDK 中的一个错误。
回答by cdespinosa
See Availability.h
请参阅可用性.h
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_2_0
etc.
等等。
回答by Brent Royal-Gordon
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).
有为操作系统的每个版本定义的预处理器宏。例如,如果__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_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