expo-task-manager with expo-location error

Please provide the following:

  1. SDK Version: "expo": "^45.0.0",
  2. IOS Emulator (atm) but all normally.
  3. expo-task-manager & expo-location

Hello, We are setting up background location tracking in our App…

I am defining my background location task before is loaded

BackgroundLocation.ts

export const LOCATION_TASK_NAME = 'background-location-task'
function init() {
  TaskManager.defineTask(LOCATION_TASK_NAME, _execute)

    setTimeout(() => {
        TaskManager.getRegisteredTasksAsync().then((tasks) =>
            console.log('registered tasks', tasks) // logs empty array
        )
    }, 5000)
}

export default { init }

App.tsx

import BackgroundLocation from '../../......'
BackgroundLocation.init()

export default App() { ... }

Now in the App component hiararchy i have a Component called <LocationTracker />

import { LOCATION_TASK_NAME } from '../../BackgroundLocation'

...

React.useEffect(() => {
  async function handleLocation() {
            try {
                if (backgroundLocationServicesEnabled) {
                    await Location.startLocationUpdatesAsync(
                        LOCATION_TASK_NAME,
                        {
                            accuracy: Location.Accuracy.Balanced,
                            distanceInterval: 20,
                        }
                    )
                } else {
                    await Location.stopLocationUpdatesAsync(
                        LOCATION_TASK_NAME
                    ).catch((e) => {
                        console.error(
                            'error calling stopLocationUpdatesAsync',
                            e
                        )
                    })
                }
            } catch (e) {
                console.error('error in handleLocation', e)
            }
        }

        handleLocation().then(() => {})
}, [backgroundServicesEnabled]) 

Background location is not enabled in my case so the error being fired is

error calling stopLocationUpdatesAsync, [Error: Task 'background-location-task' not found for app ID 'mainApplication'.]
at components/LocationTracker.tsx:70:37 in Location.stopLocationUpdatesAsync._catch$argument_0

its this part

[Error: Task ‘background-location-task’ not found for app ID ‘mainApplication’.]
that is causing me confusion because i’m registering that task ID right at the begining of the app.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.