diff --git a/ios/RCTCameraManager.m b/ios/RCTCameraManager.m index 6bb48f1..b4d2d7b 100644 --- a/ios/RCTCameraManager.m +++ b/ios/RCTCameraManager.m @@ -136,39 +136,39 @@ RCT_CUSTOM_VIEW_PROPERTY(aspect, NSInteger, RCTCamera) { RCT_CUSTOM_VIEW_PROPERTY(type, NSInteger, RCTCamera) { NSInteger type = [RCTConvert NSInteger:json]; - + self.presetCamera = type; if (self.session.isRunning) { dispatch_async(self.sessionQueue, ^{ AVCaptureDevice *currentCaptureDevice = [self.videoCaptureDeviceInput device]; AVCaptureDevicePosition position = (AVCaptureDevicePosition)type; AVCaptureDevice *captureDevice = [self deviceWithMediaType:AVMediaTypeVideo preferringPosition:(AVCaptureDevicePosition)position]; - + if (captureDevice == nil) { return; } - + self.presetCamera = type; - + NSError *error = nil; AVCaptureDeviceInput *captureDeviceInput = [AVCaptureDeviceInput deviceInputWithDevice:captureDevice error:&error]; - + if (error || captureDeviceInput == nil) { NSLog(@"%@", error); return; } - + [self.session beginConfiguration]; - + [self.session removeInput:self.videoCaptureDeviceInput]; - + if ([self.session canAddInput:captureDeviceInput]) { [self.session addInput:captureDeviceInput]; - + [NSNotificationCenter.defaultCenter removeObserver:self name:AVCaptureDeviceSubjectAreaDidChangeNotification object:currentCaptureDevice]; - + [NSNotificationCenter.defaultCenter addObserver:self selector:@selector(subjectAreaDidChange:) name:AVCaptureDeviceSubjectAreaDidChangeNotification object:captureDevice]; self.videoCaptureDeviceInput = captureDeviceInput; } @@ -176,7 +176,7 @@ RCT_CUSTOM_VIEW_PROPERTY(type, NSInteger, RCTCamera) { { [self.session addInput:self.videoCaptureDeviceInput]; } - + [self.session commitConfiguration]; }); } @@ -187,7 +187,7 @@ RCT_CUSTOM_VIEW_PROPERTY(flashMode, NSInteger, RCTCamera) { AVCaptureDevice *device = [self.videoCaptureDeviceInput device]; NSError *error = nil; NSInteger *flashMode = [RCTConvert NSInteger:json]; - + if (![device hasFlash]) return; if (![device lockForConfiguration:&error]) { NSLog(@"%@", error); @@ -214,7 +214,7 @@ RCT_CUSTOM_VIEW_PROPERTY(torchMode, NSInteger, RCTCamera) { NSInteger *torchMode = [RCTConvert NSInteger:json]; AVCaptureDevice *device = [self.videoCaptureDeviceInput device]; NSError *error = nil; - + if (![device hasTorch]) return; if (![device lockForConfiguration:&error]) { NSLog(@"%@", error); @@ -415,6 +415,7 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej #endif dispatch_async(self.sessionQueue, ^{ [self.previewLayer removeFromSuperlayer]; + [self.session commitConfiguration]; [self.session stopRunning]; for(AVCaptureInput *input in self.session.inputs) { [self.session removeInput:input]; @@ -436,7 +437,7 @@ RCT_EXPORT_METHOD(hasFlash:(RCTPromiseResolveBlock)resolve reject:(RCTPromiseRej } } } - + [self.session beginConfiguration]; NSError *error = nil;