问题
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