add output to session only when possible

This commit is contained in:
Ran Greenberg 2019-03-06 10:06:32 +02:00
parent 94c24b2c40
commit a753c508ed
1 changed files with 8 additions and 4 deletions

View File

@ -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]];
}
}
}