AVFoundation isn’t reading a specific type of barcode

喜你入骨 提交于 2019-12-25 03:27:21

问题


I’m building an app for paying parking tickets. The problem is that we have a specific type of barcode that AVFoundation can’t read.

I tried to found other frameworks to replace the AVFoundation, but turns out all of them use AVFoundation underneath. The only framework I found capable of reading it is the ZBar, but we’re not planning to use it since it hasn’t been updated for 6 years.

Do you guys have any idea why it isn’t working?

Image link https://i.stack.imgur.com/AEU0H.jpg

Thank you.

    allowedBarcodeTypes.add("org.iso.QRCode")
    allowedBarcodeTypes.add("org.iso.PDF417")
    allowedBarcodeTypes.add("org.gs1.UPC-E")
    allowedBarcodeTypes.add("org.iso.Aztec")
    allowedBarcodeTypes.add("org.iso.Code39")
    allowedBarcodeTypes.add("org.iso.Code39Mod43")
    allowedBarcodeTypes.add("org.gs1.EAN-13")
    allowedBarcodeTypes.add("org.gs1.EAN-8")
    allowedBarcodeTypes.add("com.intermec.Code93")
    allowedBarcodeTypes.add("org.iso.Code128")
    allowedBarcodeTypes.add("org.ansi.Interleaved2of5")
...
func metadataOutput(_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {

    // Check if the metadataObjects array is not nil and it contains at least one object.
    if metadataObjects.count == 0 {
        return
    }

    // Get the metadata object.
    let metadataObj = metadataObjects[0] as? AVMetadataMachineReadableCodeObject

    //videoPreviewLayer?.transformedMetadataObjectForMetadataObject(metadataObj)
    if metadataObj != nil {
        let barCode = Barcode.processMetadataObject(metadataObj)

        for str in allowedBarcodeTypes{
            if barCode?.getType() == str as? String && !didReadCode{
                    didReadCode = true
                    self.barCode = barCode?.getData() ?? ""
                    self.stopRunning()
                    if let navController = self.navigationController {
                        delegate?.getScannedCode(scannerNavigationController: navController, code: self.barCode)
                    }
                    return
            }
        }
        if didReadCode == false {
            self.invalidBarcodeFound()
        }
        return
    }
}

来源:https://stackoverflow.com/questions/53556496/avfoundation-isn-t-reading-a-specific-type-of-barcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!