From a753c508ed00abf2afe86a54d44bb30ebe637e7f Mon Sep 17 00:00:00 2001 From: Ran Greenberg Date: Wed, 6 Mar 2019 10:06:32 +0200 Subject: [PATCH] add output to session only when possible --- ios/lib/ReactNativeCameraKit/CKCamera.m | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ios/lib/ReactNativeCameraKit/CKCamera.m b/ios/lib/ReactNativeCameraKit/CKCamera.m index 21f5b44..ce0d302 100644 --- a/ios/lib/ReactNativeCameraKit/CKCamera.m +++ b/ios/lib/ReactNativeCameraKit/CKCamera.m @@ -308,10 +308,14 @@ RCT_ENUM_CONVERTER(CKCameraZoomMode, (@{ { if (onReadCode) { _onReadCode = onReadCode; - self.metadataOutput = [[AVCaptureMetadataOutput alloc] init]; - [self.session addOutput:self.metadataOutput]; - [self.metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; - [self.metadataOutput setMetadataObjectTypes:[self.metadataOutput availableMetadataObjectTypes]]; + + AVCaptureMetadataOutput * output = [[AVCaptureMetadataOutput alloc] init]; + if ([self.session canAddOutput:output]) { + self.metadataOutput = output; + [self.session addOutput:self.metadataOutput]; + [self.metadataOutput setMetadataObjectsDelegate:self queue:dispatch_get_main_queue()]; + [self.metadataOutput setMetadataObjectTypes:[self.metadataOutput availableMetadataObjectTypes]]; + } } }