Search code examples
iosios7avfoundationbarcodescanning

GTIN-14 barcodes scan with AVFoundation framework in iOS


I have to scan GTIN-14 barcodes, also named GS1-128 or ITF-14 (http://www.gtin.info/). I've tried with AVFoundation framework adding all available barcode types but it doesn't work.

- (void)startReading
{
    NSArray *barCodeTypes = @[AVMetadataObjectTypeUPCECode, AVMetadataObjectTypeCode39Code, AVMetadataObjectTypeCode39Mod43Code,
                              AVMetadataObjectTypeEAN13Code, AVMetadataObjectTypeEAN8Code, AVMetadataObjectTypeCode93Code, AVMetadataObjectTypeCode128Code,
                              AVMetadataObjectTypePDF417Code, AVMetadataObjectTypeQRCode, AVMetadataObjectTypeAztecCode];

    NSError *error;
    AVCaptureDevice *captureDevice = [AVCaptureDevice defaultDeviceWithMediaType:AVMediaTypeVideo];

    AVCaptureDeviceInput *input = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error];

    if (!input) {
        NSLog(@"%@", [error localizedDescription]);
    }

    self.captureSession = [[AVCaptureSession alloc] init];
    [self.captureSession addInput:input];


    AVCaptureMetadataOutput *captureMetadataOutput = [[AVCaptureMetadataOutput alloc] init];
    [self.captureSession addOutput:captureMetadataOutput];

    [captureMetadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()];
    [captureMetadataOutput setMetadataObjectTypes:barCodeTypes];
    //[captureMetadataOutput setMetadataObjectTypes:[captureMetadataOutput availableMetadataObjectTypes]];

    self.videoPreviewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.captureSession];
    [self.videoPreviewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
    [self.videoPreviewLayer setFrame:self.cameraView.layer.bounds];
    [self.cameraView.layer addSublayer:self.videoPreviewLayer];

    [self.captureSession startRunning];
}

It's possible with AVFoundation framework? Is there another framework to scan GTIN-14 barcodes?


Solution

  • Another barcode reader lib for ios is http://zbar.sourceforge.net.