【问题标题】:GTIN-14 barcodes scan with AVFoundation framework in iOS在 iOS 中使用 AVFoundation 框架扫描 GTIN-14 条码
【发布时间】:2014-10-30 13:36:56
【问题描述】:

我必须扫描 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 条码?

【问题讨论】:

  • 没有 GTIN-14 条码。 GTIN 是一种数据结构,可以编码为 GS1-128、ITF-14 或其他条形码。你说的“它不起作用”到底是什么意思?能发个图片链接吗?
  • 我认为您根本没有将所有支持的条形码格式添加到您的 barCodeTypes 数组中。 AVMetadataObjectTypeITF14Code 是您想要的。 ;)

标签: ios ios7 avfoundation barcode scanning


【解决方案1】:

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

【讨论】:

  • 是的,我终于使用了 CocoaPods 中的 ZBar(pod 'ZBarSDK', '~> 1.3'),它可以工作了!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-16
  • 1970-01-01
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多