2014-10-30 42 views
0

我必須掃描也稱爲GS1-128或ITF-14(http://www.gtin.info/)的GTIN-14條碼。我已經嘗試使用AVFoundation框架添加所有可用的條形碼類型,但它不起作用。iOS中的AVFoundation框架GTIN-14條碼掃描

- (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條形碼?

+0

沒有GTIN-14條碼。 GTIN是一種數據結構,可以在GS1-128,ITF-14或其他條形碼中編碼。 「它不起作用」是什麼意思?你可以發佈一個鏈接到圖像? – tobltobs 2014-11-05 12:10:22

+0

我想你只是沒有將所有支持的條形碼格式添加到你的'barCodeTypes'數組中。 [AVMetadataObjectTypeITF14Code](https://developer.apple.com/documentation/avfoundation/avmetadataobjecttypeitf14code?language=objc)就是你想要的。 ;) – 2018-02-15 13:19:42

回答

1

ios的另一個條形碼閱讀器lib是http://zbar.sourceforge.net

+0

是的,我終於使用了CocoaPods的ZBar(pod'ZBarSDK','〜> 1.3'),它的工作原理! – 2014-11-06 12:57:51