[英]Is this the proper way to detect an iPad?
我可以使用以下代码来检测我的应用程序是否在iPad上运行吗? 我的应用程序需要在iOS 3.0或更高版本上运行。
if([[[UIDevice currentDevice] model] isEqualToString:@"iPad"]){
//Do iPad stuff.
}
在iOS> = 3.2上使用UI_USER_INTERFACE_IDIOM()
宏:
if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
//device is an iPad.
}
在早期版本的iOS上,您可以回退到您的代码,即:
NSRange ipadRange = [[[UIDevice currentDevice] model] rangeOfString:@"iPad"];
if(ipadRange.location != NSNotFound) {
//Do iPad stuff.
}
这种方法是向前兼容的,因为如果明年苹果发布不同的iPad,模型名称可能会改变,但“iPad”这个词肯定会在字符串内部。
不。 改为:
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
// ...
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.