How to compare AVCaptureDevice.DeviceType to understand which one is the best option?

Viewed 853

AVCaptureDevice.DeviceType has a set of camera options and allows us to list available devices and pick one of them.

For example, the code block below lists available devices on my iPhone.

let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes:
            [.builtInTrueDepthCamera, .builtInDualCamera, .builtInWideAngleCamera, .builtInDualWideCamera, .builtInTripleCamera, .builtInTelephotoCamera, .builtInUltraWideCamera],
        mediaType: .video, position: .back)

let devices = discoverySession.devices
guard !devices.isEmpty else { fatalError("Missing capture devices.")}

devices.forEach({
   print($0.deviceType)
})

When I run this code snippet on my iPhone, I am getting the result below.

AVCaptureDeviceType(_rawValue: AVCaptureDeviceTypeBuiltInWideAngleCamera)
AVCaptureDeviceType(_rawValue: AVCaptureDeviceTypeBuiltInDualWideCamera)
AVCaptureDeviceType(_rawValue: AVCaptureDeviceTypeBuiltInUltraWideCamera)

3 devices are available on my device. How can I know that which one is the best option or the device has the highest quality? Of course, I want to pick the device which has the best quality on a user's device. Where are the differences between those there options and how can I know it during the runtime to pick the best one?

1 Answers

Setup camera

//MARK: Setup Camera
    private func setUpCamera(){
        let session = AVCaptureSession()
        if let device = AVCaptureDevice.default(AVCaptureDevice.DeviceType.builtInWideAngleCamera, for: .video, position: .front) {
            do {
                let input = try AVCaptureDeviceInput(device: device)
                if session.canAddInput(input) {
                    session.addInput(input)
                }
                if session.canAddOutput(output) {
                    session.addOutput(output)
                }
                
                previewLayer.videoGravity = .resizeAspectFill
                previewLayer.connection?.videoOrientation = .portrait
                previewLayer.session = session
                
                cameraView.layer.addSublayer(previewLayer)
                previewLayer.position = CGPoint(x: self.cameraView.frame.width/2, y: self.cameraView.frame.height/2)
                
                session.startRunning()
                self.session = session
            }
            catch let error  {
                print("Error Unable to initialize back camera:  \(error.localizedDescription)")
            }
        }
    }
Related