From 06ad9347a4399745bef0e1d012824e20e5e5a2b2 Mon Sep 17 00:00:00 2001 From: Robin Breuker Date: Thu, 17 Mar 2016 15:07:39 +0100 Subject: [PATCH] Add audio and video authorization check separately --- Camera.js | 2 ++ ios/RCTCameraManager.m | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/Camera.js b/Camera.js index 3aef332..4e88557 100644 --- a/Camera.js +++ b/Camera.js @@ -100,6 +100,8 @@ export default class Camera extends Component { }; static checkDeviceAuthorizationStatus = CameraManager.checkDeviceAuthorizationStatus; + static checkVideoAuthorizationStatus = CameraManager.checkCameraAuthorizationStatus; + static checkAudioAuthorizationStatus = CameraManager.checkAudioAuthorizationStatus; setNativeProps(props) { this.refs[CAMERA_REF].setNativeProps(props); diff --git a/ios/RCTCameraManager.m b/ios/RCTCameraManager.m index feabc60..a5e45ad 100644 --- a/ios/RCTCameraManager.m +++ b/ios/RCTCameraManager.m @@ -165,6 +165,26 @@ RCT_EXPORT_METHOD(checkDeviceAuthorizationStatus:(RCTPromiseResolveBlock)resolve }]; } + +RCT_EXPORT_METHOD(checkCameraAuthorizationStatus:(RCTPromiseResolveBlock)resolve + reject:(__unused RCTPromiseRejectBlock)reject) { + __block NSString *mediaType = AVMediaTypeVideo; + + [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) { + resolve(@(granted)); + }]; +} + +RCT_EXPORT_METHOD(checkAudioAuthorizationStatus:(RCTPromiseResolveBlock)resolve + reject:(__unused RCTPromiseRejectBlock)reject) { + __block NSString *mediaType = AVMediaTypeAudio; + + [AVCaptureDevice requestAccessForMediaType:mediaType completionHandler:^(BOOL granted) { + resolve(@(granted)); + }]; +} + + RCT_EXPORT_METHOD(changeCamera:(NSInteger)camera) { dispatch_async(self.sessionQueue, ^{ AVCaptureDevice *currentCaptureDevice = [self.videoCaptureDeviceInput device];