3

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()
MK_Pierce
  • 916
  • 2
  • 10
  • 26

1 Answers1

0

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

yoann84
  • 518
  • 1
  • 3
  • 14
  • 1
    So, I saw this method previously and follow the string of instructions, it claims we need to use a "custom build" for background permissions, and that appears to be depreciated. Is this the case? Or am I misunderstanding? – MK_Pierce Nov 04 '21 at 23:55
  • I currently have `NSLocationAlwaysUsageDescription` defined in the app.json file, but I get this error. It specifies that it is one of the `NSLocations` but it does not specify which one. Is it possible to determine which one I need? – MK_Pierce Nov 06 '21 at 01:28
  • NSLocationAlwaysUsageDescription is deprecated : https://developer.apple.com/documentation/bundleresources/information_property_list/nslocationalwaysusagedescription . You should use I think "NSLocationAlwaysAndWhenInUseUsageDescription" but I didn't test myself. – yoann84 Nov 08 '21 at 12:01
  • 1
    When I use this key, I still receive the warning – MK_Pierce Nov 08 '21 at 21:30
  • Did you find anything? – sotirelisc May 30 '22 at 16:30