Я хотел бы знать, есть ли способ выполнить функцию в диспетчере задач expo. Я пробовал несколько раз и был на этом пару дней, но приложение продолжает вылетать из-за ошибки неопределенного объекта. Ниже мой пример кода
import React from 'react';
import { Text, TouchableOpacity } from 'react-native';
import * as TaskManager from 'expo-task-manager';
import * as Location from 'expo-location';
import { connect } from 'react-redux';
import firebaseApi from './src/firebase';
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,
timeInterval: 10000,
});
};
showLocation = (location) => {
const { activeList } = this.props;
console.log('current location:', location);
firebaseApi.update({ activeList, location });
//I need it to update my firebase database
}
render() {
return (
<TouchableOpacity onPress={this.onPress} style={{marginTop: 100}}>
<Text>Enable background location</Text>
</TouchableOpacity>
);
}
}
TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {
if (error) {
console.log(error);
return;
}
if (data) {
const { locations } = data;
const latitude = locations[0].coords.latitude;
const longitude = locations[0].coords.longitude;
const loc = { latitude, longitude };
Component.showLocation(loc);
// Storing Received Lat & Long to DB by logged In User Id
// console.log("Received new locations for user = ", userId, locations);
}
});
const mapStateToProps = (state) => ({
activeList: state.userDetail.activeList,
});