Skip to content

Instantly share code, notes, and snippets.

@uddish
Last active July 5, 2020 11:27
Show Gist options
  • Save uddish/1f508e04c5050bcddd8ac8ce9bc42f2c to your computer and use it in GitHub Desktop.
Save uddish/1f508e04c5050bcddd8ac8ce9bc42f2c to your computer and use it in GitHub Desktop.
import { Platform, Alert, Linking } from 'react-native';
import { checkMultiplePermissions } from '../../services/permissions';`
// Requesting for the Microphone permission
static async checkForPermissions() {
const permissions =
Platform.OS === 'ios'
? [PERMISSIONS.IOS.MICROPHONE]
: [PERMISSIONS.ANDROID.RECORD_AUDIO];
// Call our permission service and check for permissions
const isPermissionGranted = await checkMultiplePermissions(permissions);
if (!isPermissionGranted) {
// Show an alert in case permission was not granted
Alert.alert(
'Permission Request',
'Please allow permission to access the Microphone.',
[
{
text: 'Go to Settings',
onPress: () => {
Linking.openSettings();
},
},
{
text: 'Cancel',
style: 'cancel',
},
],
{ cancelable: false },
);
}
return isPermissionGranted;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment