Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS7 barcode scanner API adds a Zero to UPCA barcode format

Scanning this (https://www.barcoderobot.com/static/bcgen/01026/478064310081_3b120.jpg?preview=True) barcode we should obtain the following result: 47806431008

Using the iOS7 api to read the barcodes, I have the following result: 047806431008

Any ideias how to deal with this?

part of the code:

CGRect highlightViewRect = CGRectZero;
AVMetadataMachineReadableCodeObject *barCodeObject;
NSString *detectionString = nil;
NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code,
                          AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code,
                          AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode];

for (AVMetadataObject *metadata in metadataObjects) {
    for (NSString *type in barCodeTypes) {
        if ([metadata.type isEqualToString:type])
        {
            barCodeObject = (AVMetadataMachineReadableCodeObject *)[_prevLayer transformedMetadataObjectForMetadataObject:(AVMetadataMachineReadableCodeObject *)metadata];
            highlightViewRect = barCodeObject.bounds;
            detectionString = [(AVMetadataMachineReadableCodeObject *)metadata stringValue];
            break;
        }
    }

    if (detectionString != nil)
    {
        [_session stopRunning];
        [self scanResult:detectionString];
        break;
    }
like image 501
Sandro Machado Avatar asked Mar 31 '14 16:03

Sandro Machado


People also ask

Why is my barcode not readable?

The most common causes of unreadable barcodes are low contrast, quiet zone violations, improper reading position, print or mark inconsistency, and damage or distortion.

What is the format of a barcode?

The basic Code 128 barcode format consists of a start code (which sets the initial character set to A, B, or C), the code data, a checksum digit, and a stop code, which marks the end of the barcode. As with other linear barcodes, there are blank quiet zones on either side.

What do the numbers at the bottom of a barcode mean?

The first six numbers of the barcode is the manufacturer's identification number. The next five digits represent the item's number. The last number is called a check digit which enables the scanner to determine if the barcode was scanned correctly.

How do you decode a barcode?

In order to decode a barcode, a specific device is required. This device will usually be a barcode scanner, although other devices like RFID sensors or even the camera of a smartphone can be used to decode a barcode. When decoding with a barcode reader, the barcode is hit by a red light coming from the barcode reader.


1 Answers

I found the problem. Apple just convert every UPC-A barcode to EAN13 just by adding a leading zero.

The solution is to verify if the barcode is EAN13 and if the string result have a leading zero is safe to remove it and obtain a UPC-A barcode.

if(detectionString!=nil){
    if([metadata.type isEqualToString:AVMetadataObjectTypeEAN13Code]){
        if ([detectionString hasPrefix:@"0"] && [detectionString length] > 1)
            detectionString = [detectionString substringFromIndex:1];
    }
}

Link to Apple technical note: https://developer.apple.com/library/content/technotes/tn2325/_index.html#//apple_ref/doc/uid/DTS40013824-CH1-IS_UPC_A_SUPPORTED_

More information in: http://www-01.ibm.com/support/docview.wss?uid=pos1R1002813

According to the Uniform Code Council, an EAN-13 barcode that begins with a zero is, by definition, a 12-digit UPC-A barcode. To follow this rule, when a scanner device reads an EAN-13 barcode beginning with a zero, it drops the leading 0, truncates the barcode to 12 digits and appends the UPC-A (instead of EAN-13) indicator to the label, before passing the label to the Operating System. Therefore, the Operating System has no way to recognize that this UPC-A label that was passed to it by the scanner device was initially an EAN-13 label beginning with a zero.

like image 179
Sandro Machado Avatar answered Nov 05 '22 09:11

Sandro Machado