Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const requestLocationPermission = async (mode: RPCChatTypes.UIWatchPositionPerm) => {
if (isIOS) {
const {Permissions} = require('react-native-unimodules')
const {status, permissions} = await Permissions.getAsync(Permissions.LOCATION)
switch (mode) {
case RPCChatTypes.UIWatchPositionPerm.base:
if (status === Permissions.PermissionStatus.DENIED) {
throw new Error('Please allow Keybase to access your location in the phone settings.')
}
break
case RPCChatTypes.UIWatchPositionPerm.always: {
const iOSPerms = permissions[Permissions.LOCATION].ios
if (!iOSPerms || iOSPerms.scope !== 'always') {
throw new Error(
'Please allow Keybase to access your location even if the app is not running for live location.'
)
}
break
}
}
}
if (isAndroid) {
const permissionStatus = await PermissionsAndroid.request(
const expoPermissionStatusMap = () => {
const {Permissions} = require('react-native-unimodules')
return {
[Permissions.PermissionStatus.GRANTED]: 'granted' as const,
[Permissions.PermissionStatus.DENIED]: 'never_ask_again' as const,
[Permissions.PermissionStatus.UNDETERMINED]: 'undetermined' as const,
}
}
const expoPermissionStatusMap = () => {
const {Permissions} = require('react-native-unimodules')
return {
[Permissions.PermissionStatus.GRANTED]: 'granted' as const,
[Permissions.PermissionStatus.DENIED]: 'never_ask_again' as const,
[Permissions.PermissionStatus.UNDETERMINED]: 'undetermined' as const,
}
}
export const requestAudioPermission = async () => {
let chargeForward = true
const {Permissions} = require('react-native-unimodules')
let {status} = await Permissions.getAsync(Permissions.AUDIO_RECORDING)
if (status === Permissions.PermissionStatus.UNDETERMINED) {
if (isIOS) {
const askRes = await Permissions.askAsync(Permissions.AUDIO_RECORDING)
status = askRes.status
} else {
const askRes = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO)
switch (askRes) {
case 'never_ask_again':
case 'denied':
status = Permissions.PermissionStatus.DENIED
}
}
chargeForward = false
}
if (status === Permissions.PermissionStatus.DENIED) {
throw new Error('Please allow Keybase to access the microphone in the phone settings.')
}