Vision scan not recognising GS1 barcode special character on iOS16

786 views Asked by At

We are using the Vision library to scan a GS1 barcode.

The library does not recognize the special character "GS" in the iOS 16 versions.

"GS" --> Group Separator character (ASCII 29)

We do not encounter such an issue on older versions. For example iOS 15.6 or lower. I've uploaded a GS1 barcode example image below.

After scanning we should be getting: {GS}10BF50001A{GS}21003032{GS}1122012722VD020

What we get instead on iOS 16 is: 10BF50001A210030321122012722VD020

I'm also posting an example code on how we use the library. We have not changed our code and the bug appears only on the iOS 16 versions. We're wondering if there's been a bug introduced.

func captureOutput(_ output: AVCaptureOutput, didOutput sampleBuffer: CMSampleBuffer, from connection: AVCaptureConnection) {
    guard let pixelBuffer = CMSampleBufferGetImageBuffer(sampleBuffer) else {
        return
    }

    let imageRequestHandler = VNImageRequestHandler(cvPixelBuffer: pixelBuffer, orientation: .right)

    do {
        try imageRequestHandler.perform([detectBarcodeRequest])
    } catch {
        logger.error(tag: TAG, "barcode error: \(error)")
    }
}

private lazy var detectBarcodeRequest = VNDetectBarcodesRequest { [weak self] request, error in
    guard error == nil else {
        self?.logger.error(tag: self?.TAG, "barcode error: \(error)")
        return
    }
    self?.processVNRequest(request)
}

private func processVNRequest(_ request: VNRequest) {
    guard let barcodes = request.results else {
        return
    }

    for barcode in barcodes {
        guard let potentialBarcode = barcode as? VNBarcodeObservation else {
            return
        }

        guard let payload = potentialBarcode.payloadStringValue else {
            return
        }

        prepareToNotifyDetectionEvent(payload)
    }
}

Thank you in advance.

GS1 Barcode example

2

There are 2 answers

1
Robin On BEST ANSWER

We had the same issue, after we updated our test device to iOS 16.0.2 our app stopped reading 2D barcodes properly (both QR Code and Data Matrix). On iOS 15, there was no issue detecting FNC1 character within the encoded data, which is used to read different GS1 elements. After the update, the app was unable to correctly detect the FNC1 character as well as other issues, which caused the workflow to be broken.

Today, we installed iOS 16.1 beta 3, I confirm that the app is working properly as intended, and the scanner is able to detect FNC1 character successfully. Everything went back to normal.

You can enroll your device in the Apple Beta Software Program to get the latest public betas, such as the one we tested out, iOS 16.1 beta 3.

Enrollment link:

https://beta.apple.com/sp/betaprogram/enroll#ios

5
Terry Burton On

The internal QR Code encoding of the message within the provided image is invalid.

The message contained therein is encoded as [ECI][BYTE]{GS}10BF40001A{GS}21003032{GS}1122012722VD020, where [ECI] is the ECI Mode indicator, [BYTE] introduces a Byte Mode segment, and {GS} is the Group Separator character (ASCII 29).

The image signals ECI, switches immediately to Byte Mode, then encodes a literal GS character. That is simply not how to encode QR Code symbols containing the GS1 Application Identifier syntax data:

  • (10) BF40001A
  • (21) 003032
  • (11) 220127
  • (22) VD020

A GS1 QR Code bitstream must start with an explicit FNC1 Mode indicator which signals "FNC1 in first place" in the message. This is incompatible with the ECI Mode indicator that is present in the given image.

The remainder of the encoding is technically correct, but highly unusual in that it used Byte Mode encoding rather than the typical Alphanumeric Mode.

Note also that the canonical separator for terminating AIs that are not pre-defined as fixed-length is the FNC1 non-data character rather than GS data character, although GS is still permissible. When FNC1 Mode is in effect, FNC1 separator characters are encoded as "%" (and literal "%" data characters are escaped as "%%") in Alphanumeric Mode, and are encoded as GS characters in Byte Mode.

The image encoder should be fixed as there would be no expectation of a successful decode for the indicated symbol.

What does the library make of the following correctly encoded symbol?

GS1 QR Code

The internal encoding of the above symbol is [FNC1][ALPHA]10BF40001A%21003032%1122012722VD020, where [FNC1] is the FNC1 Mode indicator, and [ALPHA] introduces an Alphanumeric Mode segment. (Note that the GS data characters from your original symbol are properly encoded as "%", representing FNC1 non-data characters.)