GTIN-14条形码在iOS中使用AVFoundation框架进行扫描

时间:2014-10-30 13:36:56

标签: ios ios7 avfoundation barcode scanning

我必须扫描GTIN-14条形码,也称为GS1-128或ITF-14(http://www.gtin.info/)。我已尝试使用AVFoundation框架添加所有可用的条形码类型,但它不起作用。

- (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];
}

AVFoundation框架可以实现吗?还有另一个框架来扫描GTIN-14条形码吗?

1 个答案:

答案 0 :(得分:1)

ios的另一个条形码阅读器库是http://zbar.sourceforge.net