I have a React-Native/Expo managed workflow app where I need to track a user's position when the app is running in the background.
I have successfully requested and received the user's foreground location, but the next page where the user has their background location permission requested I receive the following warning:
[Unhandled promise rejection: Error: One of the NSLocation*UsageDescription keys must be present in Info.plist to be able to use geolocation]
Here is a snippet of the code requesting 'background location'
async function getBackgroundLocationAsync() {
let { status } = await Location.requestBackgroundPermissionsAsync()
if(status !=='granted'){
setErrorMsg('Permission to access background location was denied')
return;
}
let backgroundLocation = await Location.getBackgroundPositionAsync({});
setBackgroundLocation(backgroundLocation);
}
getBackgroundLocationAsync()
The error tells exactly what you need to do : add NSLocation property in your package.json in ios.infoPlist. You'd also need to add UIBackgroundMode.
You can see the full documentation here : https://docs.expo.dev/versions/latest/sdk/location/#configuration