【问题标题】:xcode avfoundation barcode sanner how to return type of scanned codexcode avfoundation条码扫描器如何返回扫描代码的类型
【发布时间】:2021-03-10 14:52:10
【问题描述】:

Xcode 12 / 斯威夫特 5

AV基础

我按照本教程学习条形码扫描仪http://www.wepstech.com/bar-qr-code-ios-with-swift-5/

func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {     
    if let metadataObject = metadataObjects.first {
        guard let readableObject = metadataObject as? AVMetadataMachineReadableCodeObject else { return }
        guard let stringValue = readableObject.stringValue else { return }
        AudioServicesPlaySystemSound(SystemSoundID(kSystemSoundID_Vibrate))
        found(code: stringValue)
        captureSession.stopRunning()
        parent.presentationMode.wrappedValue.dismiss()
    }
}

它返回扫描的值,

但是如何获取条形码 TYPE ;要知道它是否扫描了二维码,code128...

【问题讨论】:

    标签: swift xcode avfoundation barcode-scanner


    【解决方案1】:

    您可以切换您的metadataObjecttype 属性并检查您拥有的属性:

    switch metadataObject.type {
    case .qr:
          print("qrcode")
     case .code128:
          print("code128")
     default:
          print("other type")
    }
    

    【讨论】:

    • thanks ;) 在我的情况下,我需要将它作为字符串传递给 Xcode 向我提出这个 metadataObject.type.rawValue 的函数,当我 print(metadataObject.type.rawValue) 在控制台中时,我看到了 org.iso。 qrcode... 或 org.iso.DataMatrix...
    猜你喜欢
    • 1970-01-01
    • 2013-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多