3

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?

amone
  • 3,712
  • 10
  • 36
  • 53
  • 1
    "Best" is a value judgment. What are your criteria? The camera types are listed here: https://developer.apple.com/documentation/avfoundation/avcapturedevicetypebuiltinwideanglecamera?language=objc – matt Jun 11 '20 at 21:43
  • tripleWide, dualWide, wideAngel – Aznix Jun 17 '20 at 11:00

1 Answers1

1

The problem is that the various camera options are used for different things (like true depth vs ultra wide), so there is no "best option". But I do understand what you mean... you're most likely looking for the order of the highest quality to lowest quality in terms of standard default quality of image and zoom (as-in, if you were to open your Camera app on your device and what would appear as the default).

The biggest issue with the way Apple has implemented this is that if they end up releasing a .builtInQuadCamera option in a future iPhone, for example, we'll all have to update our code to add that into our array of options to choose from to make sure our app works with the latest iPhones, when it would be nice if Apple just gave us something like .highestQualityDefault or something like that as an option.

For now, I use the following and will just have to manually update as options come along:

let deviceTypes: [AVCaptureDevice.DeviceType]
deviceTypes = [.builtInTripleCamera, .builtInDualWideCamera, .builtInDualCamera, .builtInWideAngleCamera]

let session = AVCaptureDevice.DiscoverySession(
    deviceTypes: deviceTypes,
    mediaType: .video,
    position: .back
)

guard let captureDevice = session.devices.first else {
    fatalError("No back camera device found.")
}

You will need to update your deviceTypes array as needed depending on what you're trying to accomplish.

Ethan Allen
  • 14,425
  • 24
  • 101
  • 194