Background Location not working

Hello,

I have an application which requires background location. On Android, when I minimize the app, the background location stops, I don’t know why… On iOS, appears the following warning:

Unhandled promise rejection: Error: Background Location has not been configured. To enable it, add 'location' to 'UIBackgroundModes' in Info.plist file.

On app.json I put:

“UIBackgroundModes”: [
“location”,
“fetch”
]

But still appearing this warning.

This is my defineTask code, on App.js:

TaskManager.defineTask('gelocation', async ({ data, error }) => {
	if (error) {
		return;
	}
	if (data) {
        const { locations } = data;
		console.log(locations[0].coords.latitude);
		api.postLocation(locations[0].coords.latitude, locations[0].coords.longitude,1);
	}
});

And this is where I use the Task:


    const {status, permissions} = await Permissions.askAsync(Permissions.LOCATION);
    if (status === 'granted') {
	await Location.startLocationUpdatesAsync('gelocation', {
		accuracy: Location.Accuracy.BestForNavigation,
	});
    } else {
	dispatch(fetchLocationError());
	throw new Error('Location permission not granted');
   }

Thanks a lot

1 Like

Hey @miki_kanez, is this in standalone apps, or using the Expo Client? If it’s the Expo client, let me know what version you’re using.

Also include your SDK version please, thanks!

Edit: What devices is this happening on? Seems like @napapp posted a similar issue, but it’s only a problem with iPad pro running iOS version 12.1.4

Sorry I didn’t link this before- but background location has been removed from the Expo client. So if this is on the Expo client and not a standalone app, you can follow the instructions there to work around it.

On both of them, standalone and Expo Client, on iOS. The warning message only appears on Expo, obiously. I’ll follow the Expo instructions on iOS. Thank’s.

I’m working with the new SDK expo version (32.0.0).

Now on Android only works on Expo Client but not on standalone. When I close the app, background location stops.

Thank you for your reply!

By the way, on Android 9 it doesn’t work at Expo either.

I read in some forums that decrease the frequency of the location updates, but in my case, it stops immediately. The location icon disappears.

1 Like

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