Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
window.setTimeout(async () => {
const { navigate } = this.props.navigation;
try {
const permissions = await Permissions.checkMultiple(['microphone', 'location']);
if (Platform.OS === 'ios' // Android doesn't need to handle permission explicitly
&& (permissions.microphone !== 'authorized'
|| permissions.location !== 'authorized')) {
this.props.navigation.navigate('PermissionSettings');
return;
}
const isAuthorized = await isAuthorizedAsync();
if (!isAuthorized) {
navigate('Auth');
return;
}
// Permission has been granted (for iOS only) and readerSDK has been authorized
this.props.navigation.navigate('Checkout');
return new Promise(async (resolve, reject) => {
Permissions.checkMultiple(['camera', 'photo', 'microphone']).then(response => {
// Response is one of: 'authorized', 'denied', 'restricted', or 'undetermined'
const isCameraAuthorized = response.camera === 'authorized';
const isMicrophoneAuthorized = response.microphone === 'authorized';
const isStorageAuthorized = response.photo === 'authorized';
if (isCameraAuthorized && isMicrophoneAuthorized && isStorageAuthorized) {
resolve();
} else {
Alert.alert(
'Additional Permissions Required',
recordingPermissionsErrorMessage(isCameraAuthorized, isMicrophoneAuthorized, isStorageAuthorized),
[{text: 'OK'}],
{ cancelable: false }
);
// TODO: should put it in the catch so can pass in state
Analytics.logEvent('record_video_permissions_warning', {});
reject();
checkAllPermissions = () => {
RNPermissions.checkMultiple(platformPermissions)
.then(statuses => {
console.log(statuses);
this.setState({ statuses });
})
.catch(error => {
console.error(error);
});
};
checkPermissions = () => {
Permissions.checkMultiple(['camera', 'photo']).then((response) => {
this.setPermissions(response);
});
}
async checkPermissionsAndNavigateAsync() {
try {
const permissions = await Permissions.checkMultiple(['microphone', 'location']);
if (permissions.microphone === 'authorized' && permissions.location === 'authorized') {
this.props.navigation.navigate('Splash');
return true;
}
this.updateMicrophoneState(permissions.microphone);
this.updateLocationState(permissions.location);
return false;
} catch (ex) {
Alert.alert('Permission Error', ex.message);
return true;
}
}
updatePermissions = (types: string[]) => {
Permissions.checkMultiple(types)
.then(status => {
if (this.state.isAlways) {
return Permissions.check('location', 'always').then(location => ({
...status,
location,
}));
}
return status;
})
.then(status => this.setState({status}));
};
checkPermissions = () => {
Permissions.checkMultiple(['camera', 'photo']).then(response => {
this.setPermissions(response);
});
};