From 5d306b54b8cb2670658061758ce427e9e1eecc4b Mon Sep 17 00:00:00 2001 From: Lochlan Wansbrough Date: Fri, 10 Jul 2015 12:54:14 -0700 Subject: [PATCH] Fixes bar code scanning --- RCTCameraManager.m | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/RCTCameraManager.m b/RCTCameraManager.m index 91a9f74..6fae5f6 100644 --- a/RCTCameraManager.m +++ b/RCTCameraManager.m @@ -77,6 +77,21 @@ RCT_EXPORT_VIEW_PROPERTY(torchMode, NSInteger); }; } +- (NSArray *)getBarCodeTypes { + return @[ + AVMetadataObjectTypeUPCECode, + AVMetadataObjectTypeCode39Code, + AVMetadataObjectTypeCode39Mod43Code, + AVMetadataObjectTypeEAN13Code, + AVMetadataObjectTypeEAN8Code, + AVMetadataObjectTypeCode93Code, + AVMetadataObjectTypeCode128Code, + AVMetadataObjectTypePDF417Code, + AVMetadataObjectTypeQRCode, + AVMetadataObjectTypeAztecCode + ]; +} + - (id)init { if ((self = [super init])) { @@ -271,6 +286,7 @@ RCT_EXPORT_METHOD(stopCapture) { else if (type == AVMediaTypeVideo) { self.videoCaptureDeviceInput = captureDeviceInput; } + [self.metadataOutput setMetadataObjectTypes:self.metadataOutput.availableMetadataObjectTypes]; } [self.session commitConfiguration]; @@ -440,21 +456,8 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL - (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection { - NSArray *barcodeTypes = @[ - AVMetadataObjectTypeUPCECode, - AVMetadataObjectTypeCode39Code, - AVMetadataObjectTypeCode39Mod43Code, - AVMetadataObjectTypeEAN13Code, - AVMetadataObjectTypeEAN8Code, - AVMetadataObjectTypeCode93Code, - AVMetadataObjectTypeCode128Code, - AVMetadataObjectTypePDF417Code, - AVMetadataObjectTypeQRCode, - AVMetadataObjectTypeAztecCode - ]; - for (AVMetadataMachineReadableCodeObject *metadata in metadataObjects) { - for (id barcodeType in barcodeTypes) { + for (id barcodeType in [self getBarCodeTypes]) { if (metadata.type == barcodeType) { [self.bridge.eventDispatcher sendDeviceEventWithName:@"CameraBarCodeRead"