Agontuk / react-native-geolocation-service

React native geolocation service for iOS and android
https://www.npmjs.com/package/react-native-geolocation-service
MIT License
1.61k stars 291 forks source link

watchPosition when app is closed. #403

Open theobouwman opened 1 year ago

theobouwman commented 1 year ago

Can I use this when I force close the app? Or have not even opened the app at all?

I want to track user location and maken api calls in the background.

aqil07 commented 1 year ago

Hi @theobouwman ,to achieve what you're asking, you would need to listen for AppStateChange and then do what you require, when the AppState is in the background. Refer to this: https://reactnative.dev/docs/appstate

muhammadwaqas605 commented 1 year ago

facing same issue

elibroftw commented 1 year ago

@aqil07 how would you use this? do we call watchPosition twice then? Once in foreground once in background? (on a sidenote, my research has pointed me in the direction of "foreground via persistent notification" which is the correct solution. From a user POV apps should be informing users that they are running still, I just didn't know that the app itself has to spawn that notification)

aqil07 commented 1 year ago

Hi @elibroftw , correct. When the "AppState" changes, then we call watchPosition.