【发布时间】:2011-05-19 14:09:17
【问题描述】:
可能重复:
Best way to programmatically detect iPad/iPhone hardware
我正在准备一个应用程序,我想在 iPhone 和 iPad 上使用它。
如何检测当前主机设备是iPhone还是iPad?
基于此我想对用户界面进行更改
【问题讨论】:
标签: iphone cocoa-touch ios4 device
可能重复:
Best way to programmatically detect iPad/iPhone hardware
我正在准备一个应用程序,我想在 iPhone 和 iPad 上使用它。
如何检测当前主机设备是iPhone还是iPad?
基于此我想对用户界面进行更改
【问题讨论】:
标签: iphone cocoa-touch ios4 device
有很多方法可以找到应用在哪个设备上运行。
[[[UIDevice currentDevice] systemVersion] floatValue];
通过这段代码我们可以得到当前的设备版本,这样我们就可以检查设备是否是iPad的iPhone。
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
{
// iPad-specific interface here
}
else
{
// iPhone and iPod touch interface here
}
【讨论】:
这是在运行时检测设备类型的“官方”方式:
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.
}
【讨论】: