API来确定是否在iPhone或iPad上运行

API来确定是否在iPhone或iPad上运行

本文介绍了API来确定是否在iPhone或iPad上运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有API用于在运行时检查您是在iPhone或iPad上运行?

Is there an API for checking at runtime whether you are running on an iPhone or an iPad?

我可以想到的一种方法是使用:

One way I can think of would be to use:

[[UIDevice currentDevice] model];

检测字符串@iPad的存在 - 这看起来有点脆弱。

And detect the existence of the string @"iPad" - which seems a bit fragile.

在3.2 SDK中,我看到 UIDevice 也有一个属性,这是我正在寻找的,对于3.2之前的工作(显然):

In the 3.2 SDK, I see that UIDevice also has a property which is really what I'm looking for, but doesn't work for pre-3.2 (obviously):

[[UIDevice currentDevice] userInterfaceIdiom];

有没有其他方法可以检查通用应用程序是否存在@iPad p>

Are there other ways than checking for the existence of @"iPad" for a universal app?

推荐答案

Checkout 。

Checkout UI_USER_INTERFACE_IDIOM.

返回值 br>
UIUserInterfaceIdiomPhone (如果设备是iPhone或iPod touch)或 UIUserInterfaceIdiomPad

Return Value
UIUserInterfaceIdiomPhone if the device is an iPhone or iPod touch or UIUserInterfaceIdiomPad if the device is an iPad.

用于当前设备



typedef enum {
   UIUserInterfaceIdiomPhone,
   UIUserInterfaceIdiomPad,
} UIUserInterfaceIdiom;

这篇关于API来确定是否在iPhone或iPad上运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-28 15:31