expo: Location.startLocationUpdatesAsync - not working when app killed/closed

Environment

Expo CLI 2.7.0 environment info: System: OS: macOS 10.14.3 Shell: 3.2.57 - /bin/bash Binaries: Node: 11.8.0 - /usr/local/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.5.0 - /usr/local/bin/npm Watchman: 4.9.0 - /usr/local/bin/watchman IDEs: Android Studio: 3.3 AI-182.5107.16.33.5199772 Xcode: 10.1/10B61 - /usr/bin/xcodebuild npmPackages: expo: ^32.0.0 => 32.0.2 react: 16.5.0 => 16.5.0 react-native: https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz => 0.57.1 react-navigation: ^2.18.2 => 2.18.2 npmGlobalPackages: expo-cli: 2.7.0

Steps to Reproduce

I am trying to post the device location to an API after successful login, it works as expected when the app is open/foreground/background but it does not work when the app is killed/closed

  1. TaskManager.defineTask in the main app entry point in App.js in the global scope (outside of React.Component) :

TaskManager.defineTask(TASKS_GEOLOCATION_UPDATES, ({ data: { locations }, error }) => { AsyncStorage.getItem(‘access_token’).then( accessToken => { axios.put(${getApiUrl()}/geolocation/api/location, locations, accessToken); }) });

2.Location.startLocationUpdatesAsync in a ReactComponent after successful login :

    const options = { 
        accuracy: Location.Accuracy.Balanced, 
    }

    Location.startLocationUpdatesAsync('TASKS_GEOLOCATION_UPDATES', options)

3.Change GPS location using fake GPS

4.Check API logs to check if location updates have been posted

5.Works as expected when app is open/foreground/background

6.Does NOT work when the app is killed / closed on both IOS and Android :

  • tested using Expo Client and stand alone testing builds for both Android and ios ( with Test Flight)

Expected Behavior

Expected that location updates would be sent even if the app is killed/closed . I understand that there are some limitations on Android but it does not work on ios either

Actual Behavior

No location updates are sent when the app is killed/closed Works as expected when app is open/foreground/background

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Reactions: 6
  • Comments: 30 (5 by maintainers)

Commits related to this issue

Most upvoted comments

@maayanalbert I did not find a solution, I am waiting for the next Expo SDK release which will hopefully fix this issues with geolocation.

Let me dig deeper a little bit here. I’ve clearly the same issue on android, when the app is swiped out from the task manager of the Android phone, the location updates won’t fire anymore until next time app is re-opened.

I’m analyzing a little bit these other two libs:

and actually also your background fetch here: https://github.com/expo/expo/blob/7af7d0b686832007b69f1a949ec9dca2d57c5171/packages/expo-background-fetch/android/src/main/AndroidManifest.xml

use: <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> in order to actually know when the device has booted.

But nothing is added here: https://github.com/expo/expo/blob/master/packages/expo-task-manager/android/src/main/AndroidManifest.xml or here https://github.com/expo/expo/blob/7af7d0b686832007b69f1a949ec9dca2d57c5171/packages/expo-location/android/src/main/AndroidManifest.xml where probably we would need this.

Probably I’m just talking nonsense, but I wish it might be it 😃 @tsapeta have a look please

Same issue, it will works for couple of minutes when app killed after a while it stops.

Android SDK: 36.0.0 expo-background-fetch: 8.0.0

I’m too experiencing this on android… Is there any update about this issue?

Any updates on this one? Seeing the same thing - geofencing isn’t working if the app is killed (swiped out) on iOS. Everything works fine if app is in the background.

Note, just tried with Expo 34 and still not working. More details and debug logs: https://github.com/expo/expo/issues/4860#issuecomment-516685543

@tsapeta quick update: while app is closed but another app like google maps open and if its using location services i can get the locations. Otherwise i can not get any location updates