add commitConfiguration to stopSession

This commit is contained in:
stantoncbradley 2016-06-05 12:40:32 -07:00
parent b2d9fa904b
commit 5ba2d3e40d
1 changed files with 15 additions and 14 deletions

View File

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