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: AVMediaType.video)

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: AVMediaType.video).

I just released Vidrio, a free app for macOS and Windows to make your screen-sharing awesomely holographic. Vidrio shows your webcam video on your screen, just like a mirror. Then you just share or record your screen with Zoom, QuickTime, or any other app. Vidrio makes your presentations effortlessly engaging, showing your gestures, gazes, and expressions. #1 on Product Hunt. Available for macOS and Windows.

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.