【发布时间】: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