#if __IPHONE_4_0会在iPad上运行吗? [英] Will #if __IPHONE_4_0 work on iPad?
问题描述
此检查是否适用于iPad和iPhone?我想我只是对在iPad上使用iPhone一词感到困惑。还有其他我需要检查iPad OS版本或宏是否参考一般iOS版本。
Will this check work on the iPad as well as iPhone? I guess I am just confused about using the term "iPhone" on an iPad. Is there something else I need to check for iPad OS version or does the macro refer to the general iOS version.
#if __IPHONE_4_0
// Do stuff
#elif __IPHONE_3_0
// Do 3.0 stuff
#endif
推荐答案
__ IPHONE_3_0
等问题是即使定位到其他iOS版本也会定义它们;它们是版本标识常量,而不是标识目标iOS版本的常量。使用 __ IPHONE_OS_VERSION_MIN_REQUIRED
The problem with __IPHONE_3_0
and the like is that they are defined even if targeting other iOS versions; they are version identification constants, not constants that identify the target iOS version. Use __IPHONE_OS_VERSION_MIN_REQUIRED
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_4_0
#elif __IPHONE_OS_VERSION_MIN_REQUIRED >= __IPHONE_3_0
#else
#endif
甚至:
#if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
#elif __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
#else
#endif
以解决如何定位特定的iPhone版本? __ IPHONE_OS_VERSION_MAX_ALLOWED
也可能在有限的情况下使用。
to get around the bug mentioned in the comments for "How to target a specific iPhone version?" __IPHONE_OS_VERSION_MAX_ALLOWED
might also be of use, in limited circumstances.
而且,是的,应用程序运行的设备无关紧要。这些常量由编译器定义,并且在设备上不存在。一旦预处理器运行,就不会留下任何宏。虽然设备本身存在差异,但iPhone和iPad都运行iOS,这就是你真正的目标。
And, yes, it doesn't matter what device the app will run on. These constants are defined by the compiler and don't exist on the devices. Once the pre-processor runs, no macros are left. Though there are differences in the devices themselves, the iPhone and iPad both run iOS, and that's what you're really targetting.
这篇关于#if __IPHONE_4_0会在iPad上运行吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!