How does one get UI_USER_INTERFACE_IDIOM() to work with iPhone OS SDK < 3.2

后端 未结 8 1514
旧时难觅i
旧时难觅i 2020-11-28 04:30

Apple advises using the following code to detect whether running on an iPad or iPhone/iPod Touch:

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {         


        
相关标签:
8条回答
  • 2020-11-28 05:30

    UI_USER_INTERFACE_IDIOM() and UIUserInterfaceIdiomPad can be used on iOS3.2 and upwards, the important part being the 'upwards'. Sure. iOS3.2 is only for iPad, but iOS4.0 and beyond run on both iPhones and iPads, so the check isn't as pointless as you think.

    0 讨论(0)
  • 2020-11-28 05:34

    This is what I use:

    - (BOOL) amIAnIPad {
        #if (__IPHONE_OS_VERSION_MAX_ALLOWED >= 30200)
            if ([[UIDevice currentDevice] respondsToSelector: @selector(userInterfaceIdiom)])
                return ([UIDevice currentDevice].userInterfaceIdiom == UIUserInterfaceIdiomPad);
        #endif
        return NO;
    }
    

    This conditionally compiles, so you can still build for the 3.0 sim. It then checks to see if the UIDevice class responds to the selector. If either of these fail, it's not an iPad.

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