swift - 是否可以从 iOS 读取 QR 码的纠错值?
问题描述
所有 QR 码都定义了一个纠错级别,由左下角的两个“位/像素”定义(有关详细信息,请参见此处。)虽然我知道如何在 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)
}
}
浏览文档,我还看到CIQRCodeDescriptor
(https://developer.apple.com/documentation/coreimage/ciqrcodedescriptor)确实具有我们正在寻找的价值,但我不确定如何获取要检查的实例。
解决方案
呸!它就在我面前!
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")
}
}
推荐阅读
- javascript - 重新映射对象变量大小写的干净方法
- arrays - Rust 中 array::len 的运行时复杂度是多少?
- python - 连接字符串:两个字符串列表的“乘法”
- angular - Angular Material 自动完成显示 TypeError: Cannot read property 'createEmbeddedView' of undefined
- sql - 用于分布式应用程序的 SQL Server 服务代理,其会话处于会话状态
- r - 在 R 中使用时区格式转换日期
- javascript - 如何从 jTable jQuery 中消除空行?
- java - Java中的方法返回
- c++ - 使用 make_tuple 方法获取元组和函数并返回映射元组的最简单方法
- r - 按字段拆分 data.frame 函数