As the title says, none of the Pedometer API promises resolve when called inside a task defined to be ran with Location.startLocationUpdatesAsync
and when app goes into background. The following code only works when the app is in foreground.
TaskManager.defineTask(LOCATION_TASK_NAME, async ({ data, error }) => {
if (error) {
debug('location task error: %o', error);
return;
}
if (data) {
const { locations } = data;
debug('locations received: %o', locations);
try {
const available = await Pedometer.isAvailableAsync();
debug('pedometer sensor availablity: %s', available);
} catch (err) {
debug('failed to execute background code: %o', err);
}
}
});
The task DOES get called when in the background but the Pedometer isAvailableAsync()
promise is never resolved. Is there a known fix to this? Or any workarounds to run Pedometer APIs in the background?