iPhone开发:“”型号为“iPad”返回什么?
“[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模拟器 ,当我拿到设备时会更新答案;)