“Task not found for app ID” when stopping a Background location task

Hi All,

I have created three functions in the same file, the first two are in my export default App function, with TaskManager defined globally in the file.

async startBackgroundUpdate() {
    await Location.startLocationUpdatesAsync(taskName, {
      accuracy: Location.Accuracy.Highest,
      timeInterval: 0,
      distanceInterval: 0,
    }); 
}

async stopBackgroundUpdate() {
  await Location.stopLocationUpdatesAsync(taskName)
}

TaskManager.defineTask(taskName, async ({ data, error }) => {
  if (error) {
    return console.log(error)
  }
  if (data) {
    console.log(date)
  }
});

I also have a global variable that holds the taskName

const taskName = 'geofencing'

I have a button that calls background location functions. The background location can start fine. If I query the task using TaskManager.isTaskRegisteredAsync(taskName) it confirms that a task is running. However when calling stopBackgroundUpdate I get the error:

Task 'geofencing' not found for app ID '@anonymous/track-it-fecc322d-0ade-4239-8bd1-fdcb47b0397e'.
- node_modules\react-native\Libraries\BatchedBridge\NativeModules.js:104:55 in <unknown>
- node_modules\react-native\Libraries\BatchedBridge\MessageQueue.js:414:4 in __invokeCallback
- ... 4 more stack frames from framework internals

I just can’t seem to reference the task any ideas?

Hey @adam.sinnott, what SDK version are you running?

It’s version 33 I believe.

Edit.
Just got back and checked and it is 34.0.1

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