Will #if __IPHONE_4_0 work on iPad?

后端 未结 2 1335
滥情空心
滥情空心 2021-01-20 04:35

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 O

相关标签:
2条回答
  • 2021-01-20 05:08

    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
    

    or even:

    #if __IPHONE_OS_VERSION_MIN_REQUIRED >= 40000
    #elif __IPHONE_OS_VERSION_MIN_REQUIRED >= 30000
    #else
    #endif
    

    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.

    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.

    0 讨论(0)
  • 2021-01-20 05:20

    The code you posted is a compiler directive. This means that it will not run on iPad or iPhone. It is handled when you build your app binary. Incidentally, if you're building for iPad, then you are building for 3.2, not 3.0 or 4.0.

    If you use 3_2 or 4_2 instead of 3_0 or 4_0 it should work.

    Good luck.

    0 讨论(0)
提交回复
热议问题