AVCaptureDeviceDiscoverySession

AVCaptureDeviceDiscoverySession

我目前正在使用该方法:
NSArray *captureDevices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
获取设备列表,但XCode给我警告:
Use AVCaptureDeviceDiscoverySession instead
我看过documentation,但不知道如何访问设备数组

AVCaptureDeviceDiscoverySession *session = [[AVCaptureDeviceDiscoverySession alloc]init];
???

最佳答案

根据需要创建 AVCaptureDeviceDiscoverySession ,然后调用devices方法获取符合 session 条件的当前可用设备的Array代码:

AVCaptureDeviceDiscoverySession *captureDeviceDiscoverySession = [AVCaptureDeviceDiscoverySession discoverySessionWithDeviceTypes:@[AVCaptureDeviceTypeBuiltInWideAngleCamera]
                                      mediaType:AVMediaTypeVideo
                                       position:AVCaptureDevicePositionBack];
NSArray *captureDevices = [captureDeviceDiscoverySession devices];
迅捷4+
let discoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: .video, position: .back)

10-08 05:45