所有QR码都定义了一个纠错级别,该级别由左下角的两个“位/像素”定义(有关更多详细信息,请参见here。)虽然我知道如何在Swift中扫描QR码,但我不知道如何获取我正在扫描的代码的错误纠正。
这是必需的,因为我们的应用正在尝试扫描,然后以编程方式重新创建扫描的QR码。
这是我们当前的代码,通知我们QR码扫描成功,但是我看不到任何获取QR特定细节的方法,只有成功扫描的结果...
extension QRCodeScannerViewController : AVCaptureMetadataOutputObjectsDelegate {
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
guard let metadataObject = metadataObjects.first,
let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject,
let stringValue = readableObject.stringValue else {
return
}
captureSession.stopRunning()
performSegue(withIdentifier: "ShowResults", sender: stringValue)
}
}
浏览文档,我还发现{em>确实具有我们想要的价值的CIQRCodeDescriptor
(https://developer.apple.com/documentation/coreimage/ciqrcodedescriptor),但我不确定如何获得实例进行检查。
答案 0 :(得分:0)
Du!就在我眼前!
if let qrCodeDescriptor = readableObject.descriptor as? CIQRCodeDescriptor{
switch qrCodeDescriptor.errorCorrectionLevel {
case .levelL : print("L")
case .levelM : print("M")
case .levelH : print("H")
case .levelQ : print("Q")
}
}