iPhone开发:[[UIDEVICE CurrentDevice]模型]将返回“ iPad”什么? [关闭
-
22-09-2019 - |
题
[UIDEVICE CurrentDevice]模型]将返回“ iPad”?
解决方案
您可以使用 UI_USER_INTERFACE_IDIOM()
, ,要么将返回 UIUserInterfaceIdiomPhone
或者 UIUserInterfaceIdiomPad
. 。请记住,在任何设备<3.2上,这都是不可用的,因此首先检查是否可以检索该属性 - 在这种情况下,它不是iPad。
或者,或者,要专门确定平台是否是iPad,请使用
if ([[[UIDevice currentDevice] model] containsString:@"iPad"]) {
// Your code goes here
}
希望这可以帮助 ;)
其他提示
我尝试使用containsstring,但Xcode4不允许使用。
这是我解决的方式:
if ([[[UIDevice currentDevice] model] hasPrefix:@"iPhone"])
{
希望这有助于即使有点晚。
您可以尝试 苹果开发人员论坛.
尝试模拟器:
NSLog(@"%@",[[UIDevice currentDevice] model]);
它给 iPad模拟器, ,将在我获得设备时更新答案;)
不隶属于 StackOverflow