简体   繁体   English

内置预处理器令牌来检测iPhone平台

[英]Built-in preprocessor token to detect iPhone platform

Is there a single preprocessor token that can be used to detect any iPhone device or simulator at build time? 是否有一个预处理器令牌可用于在构建时检测任何iPhone设备或模拟器? I'm currently using: 我目前正在使用:

#ifdef __IPHONE_OS_VERSION_MIN_REQUIRED
    // This is an iPhone build
#endif

Is this the recommended approach or is there a better way? 这是推荐的方法还是有更好的方法? I'd prefer the macro to be built-in, ie defined by the compiler and not by an SDK header file I have to include. 我更喜欢内置宏,即由编译器定义,而不是我必须包含的SDK头文件。

I'm not concerned about distinguishing between iPhone OS versions right now, but if there's an Apple documentation page that details all the relevant macros and when they are and aren't defined then I'd appreciate a link to it as my searching has come up short thus far. 我现在并不关心区分iPhone OS版本,但是如果有一个Apple文档页面详细说明了所有相关的宏,当它们被定义和未定义时,我会很感激它的链接,因为我的搜索已经来了到目前为止。

Thanks! 谢谢!

From this site we find that you need TARGET_OS_IPHONE 这个网站我们发现你需要TARGET_OS_IPHONE

#if TARGET_OS_IPHONE
//Do iPhone stuff
#else
//Do Mac stuff
#endif

您正在寻找的文件是TargetConditionals.h ,它定义了您感兴趣的所有宏。您可以在每个版本的SDK中找到它,如2.2 SDK的以下路径:

/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator2.2.sdk/usr/include/TargetConditionals.h

If you have code that runs on the iPhone and on the desktop, you can use TARGET_OS_IPHONE to determine if the target OS is any version of the iPhone OS. 如果您有在iPhone和桌面上运行的代码,则可以使用TARGET_OS_IPHONE来确定目标操作系统是否是任何版本的iPhone OS。 There's also TARGET_IPHONE_SIMULATOR , which is defined only when the app is being built for the simulator. 还有TARGET_IPHONE_SIMULATOR ,仅在为模拟器构建应用程序时定义。 They're still defined in header files, but I hope that helps! 它们仍然在头文件中定义,但我希望有帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM