【问题标题】:Proper method to detect device model (iPhone/iPod Touch)?检测设备型号(iPhone/iPod Touch)的正确方法?
【发布时间】:2010-03-15 13:46:03
【问题描述】:

这是检测用户正在运行的设备的正确方法吗?

NSString *currentModel = [[UIDevice currentDevice] model];
if ([currentModel isEqualToString:@"iPhone"]) {
    // The user is running on iPhone so allow Call, Camera, etc.
} else {
    // The user is running on a different device (iPod / iPad / iPhone Simulator) disallow Call.
}

【问题讨论】:

标签: iphone model detection ipod-touch


【解决方案1】:

这不是一个通用的解决方案,但 Apple 在许多情况下提供 API 调用来检查是否支持特定功能。示例可能是:

  • +isSourceTypeAvailable:+availableMediaTypesForSourceType: 中的 UIImagePickerController 允许您检查相机是否可用于当前设备。

  • +canSendMail in MFMailComposeViewController 检查设备是否配置为发送邮件。

  • -canOpenURLUIApplication 类中检查是否可以打开 URL。例如,它可以用来检查是否可以拨打电话:

    if (![[UIApplication sharedApplication] canOpenURL:
                                     [NSURL URLWithString:@"tel://"]])
        //We cannot make a call - hide call button here
    

如果此类 API 调用可用于您的目的,我会使用它们而不是依赖硬编码的字符串标识符。

【讨论】:

  • 那么这对电话有什么作用呢?我使用 tel:// 拨打一个号码,并带有一个显示该号码可以被呼叫的图标。如果用户不能直接拨打电话,我不希望显示此图标。 iPad 和 iPod Touch 就是这种情况。
  • 非常感谢弗拉基米尔!我增加了答案编号并将其标记为答案。
【解决方案2】:

我不确定我是否想概括这么多(即,最终可能会有带摄像头的 iPod,而且我不知道 iPhone 将始终被称为“iPhone”),但是是的,这是公认的方式。

【讨论】:

  • 听起来更像是评论而不是答案,不是吗?
  • 他们询问这是否是确定用户正在运行什么设备的方法。 “是”如何成为评论?
猜你喜欢
  • 2011-03-06
  • 2010-12-26
  • 2010-10-14
  • 1970-01-01
  • 2014-12-12
  • 2012-07-10
  • 2017-11-17
  • 1970-01-01
相关资源
最近更新 更多