sdk 34 startLocationUpdatesAsync/BackgroundFetch.registerTaskAsync doesn't work in background

Hi, I just update to sdk 34 and background location doesn’t work I have this:

componentDidMount() {
        Location.requestPermissionsAsync();
        BackgroundFetch.registerTaskAsync('background-locationfetch-task', {
            minimumInterval: 10,
            startOnBoot: true
        }).then(function(){ });
    }
TaskManager.defineTask('background-locationfetch-task', () => {
   try {
        let location = Location.getCurrentPositionAsync({accuracy: Location.Accuracy.Highest}).then(function (location) {
                PointController.savePoint(location).then(function(){ });
        });
        return BackgroundFetch.Result.NewData;
    } catch (error) {
        return BackgroundFetch.Result.Failed;
    }
});

and the task “background-locationfetch-task” is not called when using the real android, in simulator work as expected, how can I debug it?

I edited it in order to user BackgroundFetch but it doesn’t work

Did you resolve it yet?

It states in the docs that you can’t define the task that way:

TaskManager.defineTask(taskName, task)

Defines task function. It must be called in the global scope of your JavaScript bundle. In particular, it cannot be called in any of React lifecycle methods like componentDidMount . This limitation is due to the fact that when the application is launched in the background, we need to spin up your JavaScript app, run your task and then shut down — no views are mounted in this scenario.

Yo have to define it in another place, but to be honest, I haven’t been able to use the background fecth either, looking at the examples, the define task part shuld be outside of any class or componen, but it doesn’s seem to execute that code. Hope we can find the reason soon.

1 Like

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