我目前正在使用该方法: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)