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

6

可能重复:
检测iPad/iPhone硬件的最佳编程方式

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

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

根据这一点,我想对用户界面进行更改。


http://stackoverflow.com/questions/12479344/checking-if-users-device-is-ipad-or-iphone-ipod-difference-between-two-ways/23518735#23518735 - Waseem Shah
2个回答

11

有很多方法可以查找应用正在运行的设备。

[[[UIDevice currentDevice] systemVersion] floatValue];

通过使用这段代码,我们可以获取当前设备的版本,从而可以检查设备是否为 iPhone 或 iPad。

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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接