10

I can't seem to find any supporting documentation in the Expo docs or React Native docs that say whether or not this is possible, so I figured I'd ask here.

I'm creating an app that needs to periodically fetch the device's location, whether the app is in the foreground, background, but most important even if it's killed. Even a few times an hour is fine.

Do both Android and iOS even support this behaviour? And if so, can someone point me in the right direction or provide the class/API that I would need to make use of in Expo/React Native (ideally in Expo) that would allow me to fetch the device's location periodically even if the app is killed?

Thank you!

user1695123
  • 103
  • 1
  • 14
  • It sounds like you're asking if React-Native has a "zombie mode" where you can schedule device queries (e.g. "location"), even after the app has been incapacitated or killed. – paulsm4 Jan 11 '22 at 02:21
  • @paulsm4 Yes, pretty much – user1695123 Jan 11 '22 at 06:58
  • From a user point of view, if apple or android allow such a tracking feature, I will be more than just worried. 100% sure iOs doesn't allow this. not sure about android. – Someone Special Jan 24 '22 at 18:16
  • On iOS, I get notifications all the time about the Google Maps app using my location in the background, even when the app is dead. So I'm sure it's possible. – user1695123 Jan 24 '22 at 18:19

2 Answers2

3

Generally speaking, yes, it should be possible.

On Android, this is generally possible using a Broadcast Reciever (and see the information there regarding getting user's location up from API 28).
On iOS, this is specifically possible using the Standard Location Service (specifically refer to the section "Getting Location Events in the Background").

Focusing on React Native, then again - focusing on Expo, there is a recent post discussing just that:
The best way of tracking location in background using react-native + Expo in 2020. However, the comments there indicate that it doesn't work consistently.

Therefore, since I understand you don't specifically require using Expo (you just say "ideally in Expo" :), you can try following this React Native tutorial (June 2021): React Native background location (background & terminated app) (it uses react-native-location library).

OfirD
  • 9,442
  • 5
  • 47
  • 90
1

It seems that this could be exactly what you're looking for:

React Native — Background Location Tracking without Timeout and with App killed

https://itnext.io/react-native-background-location-tracking-without-timeout-and-with-app-killed-3dbfbc80ad01

Yann Borie
  • 44
  • 4