I'm running an EAS app where I have to use Expo-Task-Manager to handle background locations. When my app builds, I get hit with this error:
TaskManager: Task "firstTask" has been executed but looks like it is not defined. Please make
sure that "TaskManager.defineTask" is called during initialization phase.
Below is my code for executing the Task Manager in my app, but I am struggling to see where I would call it in an "initialization phase."
import * as TaskManager from 'expo-task-manager'
import * as BackgroundFetch from 'expo-background-fetch'
import * as Location from 'expo-location'
const LOCATION_TASK_NAME = 'background-location-task'
useFocusEffect(
React.useCallback(()=>{
const requestBackgroundPermissions = async() =>{
const {status} = await Location.requestBackgroundPermissionsAsync()
if(status === 'granted'){
await Location.startLocationUpdatesAsync('firstTask',{
accuracy: Location.Accuracy.Balanced,
});
}
requestBackgroundPermissions()
},
[],
),
)
//Outside of the useFocusEffect
TaskManager.defineTask('firstTask',({data,errror})=>{
if(error){
alert('Something went wrong with background locations')
}
if(data){
alert('Something went right with background locations')
const{locations} = data
}
})