检查用户的设备是ipad还是iphone / ipod,两种方式有所区别 [英] Checking if user's device is ipad or iphone/ipod, difference between two ways
问题描述
我正在阅读 Apress - 为iPhone开发人员开始iPad开发掌握iPad SDK
在一章中我读到了有关设备检查和作者写的内容:
I'm reading Apress - Beginning iPad Development for iPhone Developer Mastering the iPad SDK
and in one chapter i read about device checking and author write:
虽然您可能只想检查用户的设备类型或操作系统版本,但Apple不断发布新设备和iOS版本,这是不可取的。方法是使用NSClassFromString测试独有的iPad类的可用性。如果你将一个仅限iPad的类名称,例如UISplitViewController传递给NSClassString,并且一个有效的对象是者返回,你就会知道用户的设备是iPad ..
我不明白,为什么只需检查设备类型,例如:
I don't understand, why simply check device type for example by:
NSString *device = [[UIDevice currentDevice] model];
if ([device rangeOfString:@"iPad"].location != NSNotFound ) {
isIPad = true;
}
else isIPad = false;
比检查ipad类更差?
Is worse than checking ipad classes?
推荐答案
Apple检查自己的示例以及何时启动新的通用应用程序的方式如下:
The way that Apple checks in their own examples and when you start a new universal application is like so:
-(BOOL) isiPad {
return UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad;
}
使用模型可能不好的原因是因为你刚刚使用字符串比较。虽然我怀疑他们会改变它,但你永远不知道他们何时决定将使用 [[UIDevice currentDevice] model]
返回的字符串更改为型号或其他内容。
And the reason why using model is probably bad is because you're just using a string comparison. While I doubt they will change it, you never know when they might decide to change the string returned by using [[UIDevice currentDevice] model]
to model number or something else.
这篇关于检查用户的设备是ipad还是iphone / ipod,两种方式有所区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!