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 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 });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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];
|
||||||
|
Loading…
x
Reference in New Issue
Block a user