Best way to programmatically detect iPad/iPhone hardware

前端 未结 10 916
借酒劲吻你
借酒劲吻你 2020-11-27 14:14

The reason I need to find out is that on an iPad, a UIPickerView has the same height in landscape orientation as it does in portrait. On an iPhone it is different. The iPad

10条回答
  •  温柔的废话
    2020-11-27 14:53

    Checking at runtime (your first way) is completely different from #if at compile time. The preprocessor directives won't give you a universal app.

    The preferred way is to use Apple's Macro:

    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
         // The device is an iPad running iPhone 3.2 or later.
    }
    else
    {
         // The device is an iPhone or iPod touch.
    }
    

    Use 3.2 as the base SDK (because the macro is not defined pre 3.2), you can target prior OS versions to get it running on the iPhone.

提交回复
热议问题