Hello. I’m trying to implement the new feature “TaskManager” to get the location of device in the background. My code is very similar to the one in the docs, but when I run the code, I get the following error: "undefined is not an object (evaluating ‘_ExpoTaskManager.default.EVENT_NAME’).
Can you help me with this? I need a solution as quickly as possible.
I try to run this on an android device with Expo. Thank you !
import React from 'react';
import { Location, TaskManager } from 'expo';
import { Text, Button } from 'react-native';
const LOCATION_TASK_NAME = 'background-location-task';
export default class Component extends React.Component {
onPress = async () => {
await Location.startLocationUpdatesAsync(LOCATION_TASK_NAME, {
accuracy: Location.Accuracy.Balanced,
});
};
render() {
return (
<Button onPress={this.onPress}>
<Text>Enable background location</Text>
</Button>
);
}
}
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
}
});