Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
startWatching = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION)
if (status !== 'granted') {
// TODO: show error message
}
await Location.watchPositionAsync({
accuracy: Location.Accuracy.BestForNavigation,
timeInterval: 1000,
distanceInterval: 5
}, location => {
console.log('location', location)
})
}
async componentDidMount() {
// get exisiting locaton permissions first
const { status: existingStatus } = await Permissions.getAsync(
Permissions.LOCATION
);
let finalStatus = existingStatus;
// ask again to grant locaton permissions (if not already allowed)
if (existingStatus !== 'granted') {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
finalStatus = status;
}
// still not allowed to use location?
if (finalStatus !== 'granted') {
return;
}
const { coords } = await Location.getCurrentPositionAsync();
async function startTrace (dispatch) {
dispatch({
type: types.TRACE_START
})
let { status } = await Permissions.askAsync(Permissions.LOCATION)
if (status !== 'granted') {
// TODO: show error message
}
const watcher = await Location.watchPositionAsync({
accuracy: Location.Accuracy.BestForNavigation,
timeInterval: 1000, // TODO: get from config
distanceInterval: 5 // TODO: get from config
}, location => {
dispatch({
type: types.TRACE_POINT_CAPTURED,
location
})
})
dispatch({
type: types.TRACE_SET_SUBSCRIPTION,
watcher
async function enableLocation() {
const { status: askStatus } = await Permissions.getAsync(
Permissions.LOCATION
);
if (IOS && askStatus === "denied") {
Alert.alert(
"Permission Denied",
"To enable location, tap Open Settings, then tap on Location, and finally tap on While Using the App.",
[
{ text: "Cancel", style: "cancel" },
{
text: "Open Settings",
onPress: () => {
Linking.openURL("app-settings:");
}
}
]
);
didFocus = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
AppState.addEventListener('change', this.handleAppStateChange);
this.setState({
error:
'Location permissions are required in order to use this feature. You can manually enable them at any time in the "Location Services" section of the Settings app.',
});
return;
} else {
this.setState({ error: null });
}
const { coords } = await Location.getCurrentPositionAsync();
const isGeofencing = await Location.hasStartedGeofencingAsync(GEOFENCING_TASK);
const geofencingRegions = await getSavedRegions();
didFocus = async () => {
let { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
AppState.addEventListener('change', this.handleAppStateChange);
this.setState({
error:
'Location permissions are required in order to use this feature. You can manually enable them at any time in the "Location Services" section of the Settings app.',
});
return;
} else {
this.setState({ error: null });
}
const { coords } = await Location.getCurrentPositionAsync();
const isTracking = await Location.hasStartedLocationUpdatesAsync(LOCATION_UPDATES_TASK);
const task = (await TaskManager.getRegisteredTasksAsync()).find(
({ taskName }) => taskName === LOCATION_UPDATES_TASK
onPress={() =>
this.invokePermissionsFunction(
...([
Permissions.CAMERA,
Permissions.AUDIO_RECORDING,
Permissions.LOCATION,
Permissions.USER_FACING_NOTIFICATIONS,
Permissions.NOTIFICATIONS,
Permissions.CONTACTS,
Permissions.SYSTEM_BRIGHTNESS,
Permissions.CAMERA_ROLL,
Permissions.CALENDAR,
Permissions.REMINDERS,
] as Permissions.PermissionType[])
)
}
{ text: "Cancel", style: "cancel" },
{
text: "Open Settings",
onPress: () => {
Linking.openURL("app-settings:");
}
}
]
);
throw new Error("Permission Denied");
} else if (askStatus === "granted") {
return;
}
const { status: locationStatus } = await Permissions.askAsync(
Permissions.LOCATION
);
if (locationStatus !== "granted") {
throw new Error("Permission Denied");
}
}
_getSingleHeading = async () => {
const { status } = await Permissions.askAsync(Permissions.LOCATION);
if (status !== 'granted') {
return;
}
try {
this.setState({ searchingHeading: true });
const heading = await Location.getHeadingAsync();
this.setState({ singleHeading: heading, searchingHeading: false });
} finally {
this.setState({ searchingHeading: false });
}
}
import * as Permissions from 'expo-permissions'
import React, { useEffect, useState } from 'react'
import { Button, ScrollView, Text, View } from 'react-native'
import Example from '../example'
const permissions = [
['CAMERA', Permissions.CAMERA],
['AUDIO_RECORDING', Permissions.AUDIO_RECORDING],
['LOCATION', Permissions.LOCATION],
['USER_FACING_NOTIFICATIONS', Permissions.USER_FACING_NOTIFICATIONS],
['NOTIFICATIONS', Permissions.NOTIFICATIONS],
['CONTACTS', Permissions.CONTACTS],
['SYSTEM_BRIGHTNESS', Permissions.SYSTEM_BRIGHTNESS],
['CAMERA_ROLL', Permissions.CAMERA_ROLL],
['CALENDAR', Permissions.CALENDAR],
['REMINDERS', Permissions.REMINDERS],
]
export default function PermissionsExample() {
return (