devices(for:) was deprecated in macOS 10.15: Use AVCaptureDeviceDiscoverySession instead

In my app, I had a call to AVCaptureDevice.devices(), which looked like:

let avCaptureDevices = AVCaptureDevice.devices(for:

Since macOS 10.15, this generates this deprecation warning:

devices(for:) was deprecated in macOS 10.15: Use AVCaptureDeviceDiscoverySession instead.

Xcode sometimes gives a nice “Fix” button for deprecations, but not this time. So what is the equivalent of my old call to AVCaptureDevice.devices()? The Apple docs don’t say, but I believe it is as follows:

let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(
    deviceTypes: [ .builtInWideAngleCamera, .externalUnknown ],
    mediaType: .video,
    position: .unspecified
let avCaptureDevices = deviceDiscoverySession.devices

Non-obviously, you should include the device type .externalUnknown. If you don’t include .externalUnknown, your users won’t be able to use that fancy new camera they bought. This device type includes USB webcams, which were only implicitly included in AVCaptureDevice.devices(for:

WFH on lockdown, like me? Let’s help each other out! I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. “Oh damn that's genius”, said some YouTuber when he saw it. But don't believe him, or the #1 on Product Hunt. Instead, believe this demo:

With Vidrio

With generic competitor

More by Jim

Tagged #programming, #macos, #swift. All content copyright James Fisher 2020. This post is not associated with my employer. Found an error? Edit this page.