transistorsoft / react-native-background-geolocation

Sophisticated, battery-conscious background-geolocation with motion-detection
http://shop.transistorsoft.com/pages/react-native-background-geolocation
MIT License
2.65k stars 425 forks source link

maxRecordsToPersist only geofence events #728

Closed lkknguyen closed 5 years ago

lkknguyen commented 5 years ago

Hi Chris,

We configure to use geofence with the plugin, does it mean maxRecordsToPersist only hold geofence event, or will it also hold heart-beat, location, activity and other stuff?

We want to use the ability to re-sync event when it failed, but we only want to re-sync geofence events. Is there a way to sync only geofence event with url and maxRecordsToPersist?

Thanks,

const bgGeolocationConfig = {
  // Geofencing config
  reset: true,
  debug: false,
  // preventSuspend: true,
  logLevel: BackgroundGeolocation.LOG_LEVEL_VERBOSE,
  geofenceInitialTriggerEntry: true,
  disableMotionActivityUpdates: true, // no need for fitness motion activity on geofencing https://github.com/transistorsoft/react-native-background-geolocation/issues/386
  geofenceProximityRadius: 10000, // only activate geofences logic for ones within these radius to save battery

  // Application config
  stopOnTerminate: false, // Allow the background-service to continue tracking when user closes the app.
  startOnBoot: true,      // Auto start tracking when device is powered-up.
  enableHeadless: true,
  stationaryRadius: 100,
  heartbeatInterval: 60,
  autoSync: true,
  foregroundService: true, // headless require foreground service true
  url: API_GATEWAY_URL + '/GeofenceTransitionHandler',
  headers: {
    'Cache-Control': 'no-cache',
    'X-API-KEY': API_KEY,
    'Content-Type': 'application/json'
  },
  httpTimeout: 60000, // timeout in 60s
  httpRootProperty: '.',
  params: {
    mobileId: DeviceInfo.getUniqueID(),
    idToken: null
  },
  geofenceTemplate: '{"locationId":"<%= geofence.identifier %>", "transitionEvent":"<%= geofence.action %>"}',
  extras: {
    'via': 'background-geolocation-plugin-http'
  },
  maxRecordsToPersist: 1, // persisting only latest http event
  locationsOrderDirection: 'DESC', // sync latest one first
  // forceReloadOnGeofence: true,
  forceReloadOnBoot: true, // for android
  // Android notification config
  notificationPriority: BackgroundGeolocation.NOTIFICATION_PRIORITY_LOW,
  locationAuthorizationAlert: {
    titleWhenNotEnabled: 'Location-services not enabled',
    titleWhenOff: 'Location-services OFF',
    instructions: "Enable 'Always' in location-services for geo-fencing to work",
    cancelButton: 'Cancel',
    settingsButton: 'Settings'
  },
  notificationLargeIcon: 'mipmap/ic_launcher',
  notificationSmallIcon: 'mipmap/ic_notification'
}
christocracy commented 5 years ago

Are you using #start or #startGeofences?

To the plugin's database, everything is a location, including geofences. A geofence event is just a location with a geofence object attached.

As for heartbeat events, the plugin doesn't persist those.

If you use maxRecordsToPersist: 1 and lose network connectivity, you will lose geofence events.

You might be interested in the new Config.geofenceModeHighAccuracy.

lkknguyen commented 5 years ago

I'm using startGeofences

if you use maxRecordsToPersist: 1 and lose network connectivity, you will lose geofence events.

I thought maxRecordsToPersist and locationsOrderDirection: DESC mean "only the latest event" will be persisted, and in case of losing network connectivity, this latest event will be sent in the next device's wake up occasion (by activity change, motion change, significant location change etc...)

Thanks will check out Config.geofenceModeHighAccuracy

christocracy commented 5 years ago

maxRecordsToPersist tells the plugin that the database must only contain that many records ever.

If you tell the plugin to hold only 1 record, after each INSERT INTO, it's going to DELETE FROM such that the database contains only 1 record (the most recent INSERT)

with maxRecordsToPersist: 1, Imagine your device currently has no network connection and enters 2 geofences A and B. After entering B, A is destroyed. The database contains only 1 record: the geofence B.