代码之家  ›  专栏  ›  技术社区  ›  Mark

检测设备型号(iPhone/iPod Touch)的正确方法?

  •  2
  • Mark  · 技术社区  · 16 年前

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

    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.
    }
    
    2 回复  |  直到 14 年前
        1
  •  7
  •   Vladimir    16 年前

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

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

    • -canOpenURL 在里面 UIApplication 类来检查是否可以打开URL。例如,它可以用来检查是否可以打电话:

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

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

        2
  •  1
  •   Ben Gottlieb    16 年前

    我不确定我是否想概括这么多(也就是说,最终可能会有一个带摄像头的iPod,我不知道iPhone永远会被称为“iPhone”),但是的,这是公认的方式。

    推荐文章