Tom*_*ulc 0 iphone objective-c device ipad
我正在阅读Apress - Beginning iPad Development for iPhone Developer Mastering the iPad SDK
,在一章中我读到有关设备检查和作者写的内容:
"虽然你可能只想检查用户的设备类型或操作系统版本,但苹果不断发布新设备和iOS版本,这是不可取的.更好的方法是使用NSClassFromString测试独家iPad类的可用性如果你把一个只有iPad的类名,比如UISplitViewController传递给NSClassString,一个有效的对象是者返回,你就会知道用户的设备是iPad ......"
我不明白,为什么只需检查设备类型,例如:
NSString *device = [[UIDevice currentDevice] model];
if ([device rangeOfString:@"iPad"].location != NSNotFound ) {
isIPad = true;
}
else isIPad = false;
Run Code Online (Sandbox Code Playgroud)
比检查ipad类更糟糕吗?
Apple检查自己的示例以及何时启动新的通用应用程序的方式如下:
-(BOOL) isiPad {
return UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad;
}
Run Code Online (Sandbox Code Playgroud)
使用模型可能不好的原因是因为你只是使用字符串比较.虽然我怀疑他们会改变它,但你永远不知道他们何时决定改变使用[[UIDevice currentDevice] model]
的模型号或其他东西返回的字符串.
归档时间: |
|
查看次数: |
3904 次 |
最近记录: |