gpt4 book ai didi

ios - 适用于 iOS 9.0 的 AVCaptureDevice DiscoverySession

转载 作者:行者123 更新时间:2023-11-30 11:11:28 32 4
gpt4 key购买 nike

我正在开发 QR 和矩阵码阅读器应用程序。我正在使用 AvCaptureDevice.DiscoverySession 获取 AVCaptureDeviceInput。我的问题是它仅在 iOS 10.0 之后可用。我怎样才能获得后备版本?

// Get the back-facing camera for capturing videos
if #available(iOS 10.0, *) {
let deviceDiscoverySession = AVCaptureDevice.DiscoverySession(deviceTypes: [.builtInWideAngleCamera], mediaType: AVMediaType.video, position: .back)
guard let captureDevice = deviceDiscoverySession.devices.first else {
print("Failed to get the camera device")
return
}

} else {
// Fallback on earlier versions
}
do {
// Get an instance of the AVCaptureDeviceInput class using the previous device object.
let input = try AVCaptureDeviceInput(device: captureDevice)

// Set the input device on the capture session.
captureSession.addInput(input)

// Initialize a AVCaptureMetadataOutput object and set it as the output device to the capture session.
let captureMetadataOutput = AVCaptureMetadataOutput()
captureSession.addOutput(captureMetadataOutput)

// Set delegate and use the default dispatch queue to execute the call back
captureMetadataOutput.setMetadataObjectsDelegate(self, queue: DispatchQueue.main)

//TODO: Decide the data types!
captureMetadataOutput.metadataObjectTypes = [AVMetadataObject.ObjectType.dataMatrix]
//captureMetadataOutput.metadataObjectTypes = [AVMetadataObject.ObjectType.qr]

} catch {
// If any error occurs, simply print it out and don't continue any more.
print(error)
return
}

最佳答案

如果你想获取AVCaptureDevice列表,你可以使用

let cameras = AVCaptureDevice.devices(for: AVMediaType.video)

iOS 9

关于ios - 适用于 iOS 9.0 的 AVCaptureDevice DiscoverySession,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52145387/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com