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

后端 未结 8 1569
旧时难觅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:27

    Instead of any compiler based stuff I use:

    - (BOOL)deviceIsAnIPad {
    if ([[UIDevice currentDevice] respondsToSelector:@selector(userInterfaceIdiom)])
        //We can test if it's an iPad. Running iOS3.2+
        if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)
            return YES; //is an iPad
        else 
            return NO; //is an iPhone
    else 
        return NO; //does not respond to selector, therefore must be < iOS3.2, therefore is an iPhone
    }
    

提交回复
热议问题