xcode 是否有一个宏表示编译代码所针对的 iOS SDK 版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18170299/
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-15 03:41:19  来源:igfitidea点击:

Is there a macro that denotes the iOS SDK version against which the code is compiled?

iosxcode

提问by Vladimir Gritsenko

I.e., is it possible to know if my code is compiled under SDK 5.1, or 6.0, or any other version?

即,是否可以知道我的代码是在 SDK 5.1、6.0 或任何其他版本下编译的?

回答by miho

#ifdef __IPHONE_6_0
    // Will be ignored when compiled under SDK 5.1
#endif

When you are compiling under iOS SDK 5.1 or any other older SDK there is no #define for __IPHONE_6_0, so checking if the macro is defined helps to check the SDK version.

当您在 iOS SDK 5.1 或任何其他旧 SDK 下编译时,__IPHONE_6_0 没有 #define,因此检查宏是否定义有助于检查 SDK 版本。

回答by Michael Dautermann

Take a look at the file "Availability.h"and "AvailabilityInternal.h"in the iOS SDK and you'll see conditionals that you may be able to make use of. The Apple OpenSource ones that I linked to (which I found in this closely related question) aren't the same ones that you'll find in your SDK.

查看iOS SDK中的文件Availability.hAvailabilityInternal.h,您将看到可以使用的条件。我链接到的 Apple OpenSource 的(我在这个密切相关的问题中找到的)与您在 SDK 中找到的不同。

For example, I see a define for "__IPHONE_OS_VERSION_MIN_REQUIRED" and if you want to compile this code only on iOS 6 & newer, you'd make certain to have this set to "__IPHONE_6_0".

例如,我看到了“ __IPHONE_OS_VERSION_MIN_REQUIRED”的定义,如果您只想在 iOS 6 及更新版本上编译此代码,请确保将此设置为“ __IPHONE_6_0”。