This commit is contained in:
parent
a35ec2685f
commit
dbe8c04fdc
|
@ -1,34 +0,0 @@
|
||||||
import React from 'react';
|
|
||||||
import { Text, TouchableOpacity } from 'react-native';
|
|
||||||
import * as TaskManager from 'expo-task-manager';
|
|
||||||
import * as Location from 'expo-location';
|
|
||||||
|
|
||||||
const LOCATION_TASK_NAME = 'background-location-task';
|
|
||||||
|
|
||||||
const requestPermissions = async () => {
|
|
||||||
const { status } = await Location.requestBackgroundPermissionsAsync();
|
|
||||||
if (status === 'granted') {
|
|
||||||
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
|
|
||||||
accuracy: Location.Accuracy.Balanced,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const PermissionsButton = () => (
|
|
||||||
<TouchableOpacity onPress={requestPermissions}>
|
|
||||||
<Text>Enable background location</Text>
|
|
||||||
</TouchableOpacity>
|
|
||||||
);
|
|
||||||
|
|
||||||
TaskManager.defineTask(LOCATION_TASK_NAME, ({ data, error }) => {
|
|
||||||
if (error) {
|
|
||||||
// Error occurred - check `error.message` for more details.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (data) {
|
|
||||||
const { locations } = data;
|
|
||||||
// do something with the locations captured in the background
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
export default PermissionsButton;
|
|
Loading…
Reference in New Issue