判断设备的摄像头是否准备好



在使用条码扫描的过程中,因为有些设备(Ipad1)没有摄像头,所有想加上一个判断,如果此设备没有摄像头或者摄像头未开启,则提示用户。


【判断设备的摄像头是否准备好】判断的方法如下:



UIImagePickerController:
+ (BOOL)isCameraDeviceAvailable:(UIImagePickerControllerCameraDevice)cameraDevice
This is a class method and UIImagePickerControllerCameraDevice can take two values:

  • UIImagePickerControllerCameraDeviceRear
  • UIImagePickerControllerCameraDeviceFront


Example code:
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ]) { // 表示摄像头已经开启 }


    推荐阅读