Fix crash: check availableMetadataObjectTypes before setting QR type
This commit is contained in:
parent
32bf49fa0d
commit
8236b586c5
@ -122,7 +122,15 @@ class QRScannerWindowController: NSObject, AVCaptureMetadataOutputObjectsDelegat
|
||||
if session.canAddOutput(output) {
|
||||
session.addOutput(output)
|
||||
output.setMetadataObjectsDelegate(self, queue: .main)
|
||||
output.metadataObjectTypes = [.qr]
|
||||
// 检查摄像头是否支持 QR 码识别
|
||||
if output.availableMetadataObjectTypes.contains(.qr) {
|
||||
output.metadataObjectTypes = [.qr]
|
||||
} else {
|
||||
DispatchQueue.main.async { [weak self] in
|
||||
self?.showError("Camera does not support QR code scanning")
|
||||
}
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
let previewLayer = AVCaptureVideoPreviewLayer(session: session)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user