From 2f4605d75beb5c60f9cc9b36d649e6551749cbb4 Mon Sep 17 00:00:00 2001 From: Antti Moilanen Date: Wed, 29 Mar 2017 15:38:22 +0300 Subject: [PATCH] Added a check that AVCaptureConnection is enabled before trying to do the capture. Fixes a crash that happened sometimes if taking multiple images fast. --- ios/RCTCameraManager.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ios/RCTCameraManager.m b/ios/RCTCameraManager.m index bd611f0bd..09d1043ee 100644 --- a/ios/RCTCameraManager.m +++ b/ios/RCTCameraManager.m @@ -574,8 +574,12 @@ - (void)captureStill:(NSInteger)target options:(NSDictionary *)options orientati [self saveImage:imageData target:target metadata:nil resolve:resolve reject:reject]; #else [[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] setVideoOrientation:orientation]; - - [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { + AVCaptureConnection *connection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo]; + if (!connection.enabled) { + reject(RCTErrorUnspecified, nil, RCTErrorWithMessage(@"RCTCamera: AVCaptureConnection for the image output not enabled anymore.")); + return; + } + [self.stillImageOutput captureStillImageAsynchronouslyFromConnection:connection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) { if (imageDataSampleBuffer) { NSData *imageData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];