mirror of
https://github.com/status-im/react-native-camera.git
synced 2025-02-24 17:58:20 +00:00
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:
commit
c981675636
@ -113,6 +113,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);
|
||||
@ -129,8 +131,10 @@ export default class Camera extends Component {
|
||||
async componentWillMount() {
|
||||
this.cameraBarCodeReadListener = NativeAppEventEmitter.addListener('CameraBarCodeRead', this.props.onBarCodeRead);
|
||||
|
||||
if (Camera.checkDeviceAuthorizationStatus) {
|
||||
const isAuthorized = await Camera.checkDeviceAuthorizationStatus();
|
||||
let check = this.props.captureAudio ? Camera.checkDeviceAuthorizationStatus : Camera.checkVideoAuthorizationStatus;
|
||||
|
||||
if (check) {
|
||||
const isAuthorized = await check();
|
||||
this.setState({ isAuthorized });
|
||||
}
|
||||
}
|
||||
|
@ -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) {
|
||||
dispatch_async(self.sessionQueue, ^{
|
||||
AVCaptureDevice *currentCaptureDevice = [self.videoCaptureDeviceInput device];
|
||||
|
Loading…
x
Reference in New Issue
Block a user