react-native-background-geolocation icon indicating copy to clipboard operation
react-native-background-geolocation copied to clipboard

[Help Wanted]: Attach app state metadata to location before persisted in SQLite for retrieval via getLocations()

Open chhoangphi opened this issue 6 months ago • 4 comments

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


chhoangphi avatar May 30 '25 10:05 chhoangphi

Do you know how to set up an AppState event-listener for your react-native app?

christocracy avatar May 30 '25 15:05 christocracy

Do you know how to set up an AppState event-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?

chhoangphi avatar May 30 '25 16:05 chhoangphi

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.

christocracy avatar May 30 '25 16:05 christocracy

Thanks your support

chhoangphi avatar May 30 '25 16:05 chhoangphi

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] avatar Jul 03 '25 02:07 github-actions[bot]

This issue was closed because it has been inactive for 14 days since being marked as stale.

github-actions[bot] avatar Jul 17 '25 02:07 github-actions[bot]