简体   繁体   中英

How to check if iPhone has dual camera?

I'm writing a photo app and I need different overlays in the camera view for iPhones with dual camera (to account for the zoom ui), is there a proper way to check if a dual camera exists?

I tried to get the device and check if it was nil for the non dual camera iPhones, tho it still retunes a device:

let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInDualCamera, mediaType: AVMediaTypeVideo, position: .back)

Dose anyone know how to detect the dual camera?

Just as the apple's example:

if let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInDuoCamera,
                                                  mediaType: AVMediaTypeVideo,
                                                  position: .back) {
        return device
    } else if let device = AVCaptureDevice.defaultDevice(withDeviceType: .builtInWideAngleCamera,
                                                  mediaType: AVMediaTypeVideo,
                                                  position: .back) {
        return device
    } else {
        return nil
    }

Swift 5 :

var currentDevice:AVCaptureDevice?

     if let device = AVCaptureDevice.default(.builtInDualCamera, for: AVMediaType.video, position: .back) {

                currentDevice = device

         } else if let device = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .back) {

                currentDevice = device

            } else {

                print("Error: no camera available")
            }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM