【问题标题】:How to detect whether the host device is iPhone or iPad? [duplicate]如何检测主机设备是iPhone还是iPad? [复制]
【发布时间】:2011-05-19 14:09:17
【问题描述】:

可能重复:
Best way to programmatically detect iPad/iPhone hardware

我正在准备一个应用程序,我想在 iPhone 和 iPad 上使用它。

如何检测当前主机设备是iPhone还是iPad?

基于此我想对用户界面进行更改

【问题讨论】:

标签: iphone cocoa-touch ios4 device


【解决方案1】:

有很多方法可以找到应用在哪个设备上运行。

[[[UIDevice currentDevice] systemVersion] floatValue];

通过这段代码我们可以得到当前的设备版本,这样我们就可以检查设备是否是iPad的iPhone。

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
    // iPad-specific interface here
}
else
{
    // iPhone and iPod touch interface here
}

【讨论】:

    【解决方案2】:

    这是在运行时检测设备类型的“官方”方式:

    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.
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-18
      • 2012-10-25
      • 1970-01-01
      • 2018-03-14
      • 1970-01-01
      相关资源
      最近更新 更多