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.64k stars 425 forks source link

geofences are not being saved when app in killed state #1938

Closed DevSomya2000 closed 6 months ago

DevSomya2000 commented 8 months ago

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

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) ```
christocracy commented 8 months ago

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

christocracy commented 8 months ago

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.

ankitjainOfficial commented 8 months ago

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.

christocracy commented 8 months ago

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 #

ankitjainOfficial commented 8 months ago

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();
christocracy commented 8 months ago

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.

ankitjainOfficial commented 8 months ago

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?

christocracy commented 8 months ago

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"?

github-actions[bot] commented 6 months ago

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

github-actions[bot] commented 6 months ago

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