I\'m writing an iOS app, and I need to be able to detect if the device has a camera. Previously, I would check if the device is an iPhone or not, since only the iPhone has a
If you need to know whether the device specifically has a front or rear camera, use this:
isCameraAvailable = [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
To check of camera is available (Swift)
if(!UIImagePickerController.isSourceTypeAvailable(UIImagePickerControllerSourceType.Camera))
Swift:
if UIImagePickerController.isSourceTypeAvailable(.Camera){
//Your code goes here
//For example you can print available media types:
print(UIImagePickerController.availableMediaTypesForSourceType(.Camera))
}
You can use +isSourceTypeAvailable:
method in UIImagePickerController:
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
// Has camera
Yes, there is an API provided to do just that:
BOOL isCamera = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
You can check for availability of a specific source type using discovery session (Swift 5):
let discovery = AVCaptureDevice.DiscoverySession.init(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .back)
let isWideAngleCameraSupported = !discovery.devices.isEmpty