react-native-background-geolocation
react-native-background-geolocation copied to clipboard
[Help Wanted]: Attach app state metadata to location before persisted in SQLite for retrieval via getLocations()
Required Reading
- [x] Confirmed
Plugin Version
lastest
Mobile operating-system(s)
- [x] iOS
- [ ] Android
Device Manufacturer(s) and Model(s)
Iphone 14
Device operating-systems(s)
ios 18.1
React Native / Expo version
0.76.6
What do you require assistance about?
I would like to attach app-specific metadata (e.g. app state: active or inactive) to each location before it is persisted into the SDK’s SQLite database.
Goal:
- When the app receives a new location, I want to associate it with the app state at that time (e.g. background/foreground).
- Later, when calling
BackgroundGeolocation.getLocations(), I want to retrieve those persisted locations along with the custom metadata for further processing.
From what I’ve read, the extras field is only attached at HTTP request time, not when the location is stored in SQLite by the SDK. This means if the device is offline or if the app state changes after the location was recorded, there’s no way to retroactively know the state at record time from the persisted location.
Thanks in advance for the clarification!
[Optional] Plugin Code and/or Config
[Optional] Relevant log output
Do you know how to set up an AppState event-listener for your react-native app?
Do you know how to set up an
AppStateevent-listener for your react-native app?
Yes, I know how to set up an AppState event listener in a React Native app. I have an appState variable (which can change frequently between values like active, background, or inactive), and I want to attach it to each location before it’s persisted into SQLite by library.
How can I properly do that?
In your AppState listener, call .setConfig to change the Config.extras, as desired.
BackgroundGeolocation.setConfig({
extras: {"app_state": appState.current}
});
Every new recorded location will be stamped with those new extras.
Thanks your support
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.