Fixes bar code scanning

This commit is contained in:
Lochlan Wansbrough 2015-07-10 12:54:14 -07:00
parent 65b5033596
commit 5d306b54b8
1 changed files with 17 additions and 14 deletions

View File

@ -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 { - (id)init {
if ((self = [super init])) { if ((self = [super init])) {
@ -271,6 +286,7 @@ RCT_EXPORT_METHOD(stopCapture) {
else if (type == AVMediaTypeVideo) { else if (type == AVMediaTypeVideo) {
self.videoCaptureDeviceInput = captureDeviceInput; self.videoCaptureDeviceInput = captureDeviceInput;
} }
[self.metadataOutput setMetadataObjectTypes:self.metadataOutput.availableMetadataObjectTypes];
} }
[self.session commitConfiguration]; [self.session commitConfiguration];
@ -440,21 +456,8 @@ didFinishRecordingToOutputFileAtURL:(NSURL *)outputFileURL
- (void)captureOutput:(AVCaptureOutput *)captureOutput didOutputMetadataObjects:(NSArray *)metadataObjects fromConnection:(AVCaptureConnection *)connection { - (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 (AVMetadataMachineReadableCodeObject *metadata in metadataObjects) {
for (id barcodeType in barcodeTypes) { for (id barcodeType in [self getBarCodeTypes]) {
if (metadata.type == barcodeType) { if (metadata.type == barcodeType) {
[self.bridge.eventDispatcher sendDeviceEventWithName:@"CameraBarCodeRead" [self.bridge.eventDispatcher sendDeviceEventWithName:@"CameraBarCodeRead"