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

geofences are not being saved when app in killed state

Open DevSomya2000 opened this issue 1 year ago • 8 comments

When the geofence event is triggered for configured geofences, the geofences are not getting inserted to sqlite database of locations as per the geolocation logs.

Below is provided one example: Screenshot 2024-02-08 at 5 44 46 PM

The geofences events should have been inserted to the location database like the below provided image for onheartbeat event: Screenshot 2024-02-08 at 5 49 59 PM

Your Environment

  • Plugin version: 4.14.5
  • Platform: iOS
  • OS version: 17.1.2
  • Device manufacturer / model: Apple / iPhone 12 mini
  • React Native version (react-native -v): 0.72.3
  • Plugin config
        url: `${url}/geofence`,
        headers: {
          authorization: `Bearer ${token}`,
        },
        autoSync: true,
        autoSyncThreshold: 2,
        batchSync: true,
        maxBatchSize: 2,
        // locationsOrderDirection: 'DESC',
        maxDaysToPersist: 3,
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        enableHeadless: true,
        distanceFilter: 10,
        stopOnTerminate: false,
        locationAuthorizationRequest: 'Always',
        backgroundPermissionRationale: {
          title: "Allow access to this device's location in the background?",
          message:
            'We use your location to assist in your continued journey to well being by monitoring breaches to inclusion/exclusion zones set up or allowed by you even when you are not using the app',
          positiveAction: 'Change to allow all the time',
          negativeAction: "I'm not sure about this",
        },
        geofenceInitialTriggerEntry: true,
        scheduleUseAlarmManager: true,
        heartbeatInterval: 60,
        logLevel: 5,
        startOnBoot: true,
        preventSuspend: true,
        geofenceModeHighAccuracy: true,
        geofenceProximityRadius: 1000,
        stopTimeout: 15,
        schedule: [
          '1-7 10:00-10:30 location',
          '1-7 12:00-12:30 location',
          '1-7 14:00-14:30 location',
          '1-7 16:00-16:30 location',
          '1-7 18:00-18:30 location',
          '1-7 20:00-20:30 location',
          '1-7 00:00-23:59 geofence',
        ],
        enableTimestampMeta: true,
        disableElasticity: true,

Expected Behavior

Expected to get the insert logs of geofence events in database in geolocation logs and get synced to HTTP URL

Actual Behavior

the geofence events are not getting saved to database.

Steps to Reproduce

  1. The app was in killed state. (removed from background tasks)
  2. There was network connectivity. (From cellular network)
  3. Was moving in a vehicle crossing the geofences.

Context

Debug logs

Logs
[background-geolocation.log](https://github.com/transistorsoft/react-native-background-geolocation/files/14209285/background-geolocation.log)

DevSomya2000 avatar Feb 08 '24 12:02 DevSomya2000

Show me the geofences you're adding (I want to see all the attributes you're using).

christocracy avatar Feb 08 '24 14:02 christocracy

Also, based upon your schedule, those geofences (fired at 16:38 and 16:43) should not be recorded.

"1-7 16:00-16:30 location",
"1-7 18:00-18:30 location",
2024-02-08 16:38:15.700 🎾-[TSGeofenceManager locationManager:didEnterRegion:] dccaedc6-adb5-49ac-95a0-7209600128b4

2024-02-08 16:38:15.700 🔴-[TSGeofenceManager locationManager:didExitRegion:] 0d7f0fd1-fc4b-47f1-a50a-17c12c4ffe46

Looking closer at your schedule '1-7 00:00-23:59 geofence',, you seem to think that multiple schedule entries can be applied simultaneously. That's not how the scheduler works. The scheduler operates by applying the first match.

christocracy avatar Feb 08 '24 15:02 christocracy

ok, got the point. But, what should we do, if we want to track geofences always and schedule periodic location updates?

Sidenote: We've purchased a licence, but we don't have access to the private repo, which I believe is frequently updated.

ankitjainOfficial avatar Feb 08 '24 15:02 ankitjainOfficial

But, what should we do, if we want to track geofences always and schedule periodic location updates?

You have to declare each specific schedule interval accordingly. Only one schedule entry is activated at any particular time.

We've purchased a licence, but we don't have access to the private repo, which I believe is frequently updated.

Email me your Order #

christocracy avatar Feb 08 '24 15:02 christocracy

Can we do this:

const state = await BackgroundGeolocation.ready({
        url: `${url}/geofence`,
        headers: {
          authorization: `Bearer ${token}`,
        },
        autoSync: true,
        autoSyncThreshold: 2,
        batchSync: true,
        maxBatchSize: 2,
        locationsOrderDirection: 'ASC',
        maxDaysToPersist: 3,
        desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_HIGH,
        enableHeadless: true,
        distanceFilter: 10,
        stopOnTerminate: false,
        locationAuthorizationRequest: 'Always',
        backgroundPermissionRationale: {
          title: "Allow access to this device's location in the background?",
          message:
            'We use your location to assist in your continued journey to well being by monitoring breaches to inclusion/exclusion zones set up or allowed by you even when you are not using the app',
          positiveAction: 'Change to allow all the time',
          negativeAction: "I'm not sure about this",
        },
        geofenceInitialTriggerEntry: true,
        scheduleUseAlarmManager: true,
        heartbeatInterval: 60,
        logLevel: 5,
        startOnBoot: true,
        geofenceModeHighAccuracy: true,
        schedule: [
          '1-7 10:00-10:30 location',
          '1-7 12:00-12:30 location',
          '1-7 14:00-14:30 location',
          '1-7 16:00-16:30 location',
          '1-7 18:00-18:30 location',
          '1-7 20:00-20:30 location',
        ],
        enableTimestampMeta: true,
        disableElasticity: true,
      });

      await BackgroundGeolocation.startGeofences();
      await BackgroundGeolocation.startSchedule();
      ```

ankitjainOfficial avatar Feb 08 '24 15:02 ankitjainOfficial

Can we do this:

When you call .startSchedule(), the plugin is going to iterate the schedule, select the first matching entry and apply it. It is going to ask itself "based upon this period, should I be ON or OFF?". If that particular entry says the plugin should be OFF, it's going to call .stop() upon itself. The Scheduler is a robot that calls .stop() and .start() / .startGeofences() upon itself based upon the first matching schedule entry.

So no, you can't do that.

christocracy avatar Feb 08 '24 15:02 christocracy

Thank you for the explanation. That cleared a lot. But, I'm still stuck as how to get periodic location for my user with geofences active all the time?

ankitjainOfficial avatar Feb 08 '24 15:02 ankitjainOfficial

You need to "fill in the blanks" with your schedule with geofence entries.

Look at your first entry: What is supposed to happen before 10:00?

'1-7 10:00-10:30 location',

Perhaps this:

'1-7 00:00-9:59 geofence`

Go through each entry and ask yourself "what is supposed to happen before this entry".

When you get to the last entry, ask yourself "what is supposed to happen after this entry"?

christocracy avatar Feb 08 '24 15:02 christocracy

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

github-actions[bot] avatar Apr 17 '24 01:04 github-actions[bot]

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

github-actions[bot] avatar May 01 '24 01:05 github-actions[bot]