Location.startLocationUpdatesAsync and foregroundService are not working as expected
See original GitHub issue🐛 Bug Report
Environment
Expo CLI 2.19.4 environment info: System: OS: macOS 10.14.4 Shell: 3.2.57 - /bin/bash Binaries: Node: 10.15.3 - /usr/local/bin/node Yarn: 1.13.0 - /usr/local/bin/yarn npm: 6.4.1 - /usr/local/bin/npm IDEs: Xcode: 10.2.1/10E1001 - /usr/bin/xcodebuild npmPackages: expo: ^33.0.0 => 33.0.5 react: 16.8.3 => 16.8.3 react-native: https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz => 0.59.8 react-navigation: ^3.11.0 => 3.11.0 npmGlobalPackages: expo-cli: 2.19.4
My target platform is Android. I am using expo SDK version 33. (This is reproducable in SDK 32 also)
Steps to Reproduce
Download this snack, it only works on a real phone (you can’t reproduce this with simulated/fake locations, and android emulators).
Run the app, and then navigate away from it in the os. Now when you go back, an alert should appear that shows how many location updates occured while the app was in the background state.
Expected Behavior
The application, should recice at least some location updates while in the background, and this should be aligned with the arguments passed to the Location.startLocationUpdatesAsync function. When using the new foregroundService atribute, the app should get location updates as frequently as if it was in the foreground state.
Actual Behavior
This is not the case, for a real device and real locations, you do not get any updates, the alert always shows 0 no mater how far you go. However you will recieve location updates if you use some kind of simulated/mock/fake location. (It does not matter if you create a foregroundService or not, and this is reproduceable in a standalone app too, not just the expo client! )
Reproducible Demo
The snack is here, you should download it and run it on a real device.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:17 (2 by maintainers)
Top Related StackOverflow Question
I get it when compiling the app as stand alone. Doesn’t show up when running it in the Expo client.
I could have sworn I saw a fix for this merged after the release of the latest 32-version, but I can’t find the issue atm. Was expecting this to work in 33, but I am unfortunately having the same issue as @Dewyer : my app stops updating the background location as soon as I lock my phone or switch to another app.
Perhaps I/we are using it incorrectly? It would be nice if the documentation could be updated with information on how to get background location updates working. For instance: I can’t find anything about the property
foregroundService(if it is indeed a valid property forLocation.startLocationUpdatesAsync.