devices(for:) was deprecated in macOS 10.15: Use AVCaptureDeviceDiscoverySession instead
In my app, I had a call to
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
Xcode sometimes gives a nice “Fix” button for deprecations,
but not this time.
So what is the equivalent of my old call to
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
If you don’t include
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
Tagged #programming, #macos, #swift. All content copyright James Fisher 2020. This post is not associated with my employer.