AVCaptureMetadataOutput does not detects string value from some barcode

I am using AVFoundation to detect bar code and it is working for most of the bar code, I can get the string value from the bar code.


func metadataOutput(_ captureOutput: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection) {
     if let barcodeData = metadataObjects.first {
          if let readString = (barcodeData as? AVMetadataMachineReadableCodeObject)?.stringValue, readString != "" {
               print("barcode found, \(readString)")       
          }
     }
}

above method dose work most of the time but I found one barcode to which it return empty string. I downloaded few barcode scanner from Apple App Store and they were able to detect the stringValue. I downloaded sample code from https://developer.apple.com/library/content/samplecode/AVCamBarcode/Introduction/Intro.html and it did not work as well. I have also included all barcode type provided by apple in metadataObjectTypes just to make sure that I am not missing something. I have attached barcode which does not return the value.

Replies

You should file a bug report at bugreport.apple.com, and be sure to include a picture of the barcode that didn't work. The empty string is the expected return value when there were no utf8 symbols in the payload, or if the very beginning of the payload consisted of non-utf8-representable data, or if the payload contained only control symbols.


Similarly, a decoding error (where the payload can’t be parsed correctly but error correction succeeds) typically results in a null stringValue.

I´m using the same code to get stringvalue from AVMetadataMachineReadableCodeObject but i can´t get it to return the complete string representation.
I have this barcode: https://drive.google.com/file/d/1-9jnHCObYrjJXxgJu8dauYDL56Oskw04/view?usp=sharing
and stringvalue returns: 034486174
instead i should be getting something like: 034486174���������������PubDSK_1��������240861��1098673211CABARIQUE��������������ENSUNCHO���������������LUIS�������������������ALONSO�������


It seems stringvalue is cropping the text it can't represent. Is there any other way to get stringvalue representation without beign cropped? maybe Data representation without the the format of the machine-readable code.

Can I get the raw data of the data scanned?