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
}
}
export async function getLocation (opts = {}) {
const status = await askAsyncPermissions(Permissions.LOCATION)
if (status !== 'granted') {
const res = {errMsg: `Permissions denied!`}
return Promise.reject(res)
}
if (!opts || typeof opts !== 'object') {
opts = {}
}
const {altitude = false, success, fail, complete} = opts
return new Promise((resolve, reject) => {
Location.getCurrentPositionAsync({
enableHighAccuracy: Boolean(altitude)
}).then((resp) => {
const {coords, timestamp} = resp
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(
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
{
buttonNegative: 'Cancel',
buttonPositive: 'OK',
message: 'Keybase needs access to your location in order to post it.',