Merge pull request #230 from niborb/feature/add-audio-and-video-authorization-check

Add audio and video authorization check separately
This commit is contained in:
Zack Story 2016-04-03 11:09:34 -07:00
commit c981675636
2 changed files with 26 additions and 2 deletions

View File

@ -113,6 +113,8 @@ export default class Camera extends Component {
}; };
static checkDeviceAuthorizationStatus = CameraManager.checkDeviceAuthorizationStatus; static checkDeviceAuthorizationStatus = CameraManager.checkDeviceAuthorizationStatus;
static checkVideoAuthorizationStatus = CameraManager.checkCameraAuthorizationStatus;
static checkAudioAuthorizationStatus = CameraManager.checkAudioAuthorizationStatus;
setNativeProps(props) { setNativeProps(props) {
this.refs[CAMERA_REF].setNativeProps(props); this.refs[CAMERA_REF].setNativeProps(props);
@ -129,8 +131,10 @@ export default class Camera extends Component {
async componentWillMount() { async componentWillMount() {
this.cameraBarCodeReadListener = NativeAppEventEmitter.addListener('CameraBarCodeRead', this.props.onBarCodeRead); this.cameraBarCodeReadListener = NativeAppEventEmitter.addListener('CameraBarCodeRead', this.props.onBarCodeRead);
if (Camera.checkDeviceAuthorizationStatus) { let check = this.props.captureAudio ? Camera.checkDeviceAuthorizationStatus : Camera.checkVideoAuthorizationStatus;
const isAuthorized = await Camera.checkDeviceAuthorizationStatus();
if (check) {
const isAuthorized = await check();
this.setState({ isAuthorized }); this.setState({ isAuthorized });
} }
} }

View File

@ -172,6 +172,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) { RCT_EXPORT_METHOD(changeCamera:(NSInteger)camera) {
dispatch_async(self.sessionQueue, ^{ dispatch_async(self.sessionQueue, ^{
AVCaptureDevice *currentCaptureDevice = [self.videoCaptureDeviceInput device]; AVCaptureDevice *currentCaptureDevice = [self.videoCaptureDeviceInput device];