Objective C 方法检测所使用的设备是否是 iPod
我正在尝试找到一种方法来检测所使用的设备是否是 iPod touch,有吗?
我在 iPad 上使用此方法...
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
....
}
I am trying to find a way to detect if the device used is an iPod touch, is there any?
I am using this method for the iPad...
if (UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
....
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你为什么想知道?如果是因为你想知道是否有摄像头或可以打电话等,那么你最好通过功能检测来做到这一点(以防苹果在某个时候制造出带有手机的 iPod!),例如 Cliff 的回答。
如果是出于其他原因,而您确实只想知道它是 iPod 还是 iPhone,而不考虑实际设备功能,请按以下步骤操作:
Why do you want to know? If it's because you want to know if has a camera or can make phone calls etc. then you'd be better off doing this with feature detection (in case Apple make an iPod with a phone in it at some point!) such as Cliff's answer.
If it's for some other reason and you really do just want to know if it's an iPod or iPhone, irrespective of the actual device capabilities, here's how you do it:
我过去利用过的一个粗略的黑客方法是查询设备是否可以拨打电话#。我忘记了语法,但应该有类似的东西
,老实说,我更喜欢这种方法而不是绝对检测,因为它侧重于设备的功能而不是模型。最好根据设备的功能而不是模型来条件化逻辑,因为您永远不知道未来版本的 iOS 设备将引入哪些功能。例如,如果设备类型 == iPad,则隐藏视频控件在一年前还具有实际意义,但当 iPad2 在几个月内推出时,该功能就会受到限制。如果您假设仅仅因为该设备是 iPod,您应该或不应该执行功能 X,那么您将限制该产品的进一步版本中的功能(如果添加该功能)。
A rough hack that I've exploited in the past is to query whether the device can dial a phone#. I forget the syntax offhand but there should be something like
Honestly, I prefer this approach over absolute detection because it focuses on capabilities of the device rather than the model. It's better to conditionalize logic based on what the device is capable of rather than on the model because you never know what capabilities will be introduced in future release of iOS devices. For instance, hiding video controls if device type == iPad would have made practical sense just over a year ago but would have limited that functionality when the iPad2 was introduced in a matter of months. If you assume just because the device is an iPod that you should or should not do features X then you will limit functionality on further releases of the product should the capability be added.