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

DWELL / loiteringDelay is not detected for Polygon Geofences IOS

Open sirusbaladi opened this issue 1 year ago • 14 comments

Your Environment

  • Expo
  • Plugin version: 4.16.5
  • Platform: iOS
  • OS version: 17.4.1
  • Device manufacturer / model: Iphone 13 pro
  • React Native version (react-native -v): "0.71.14
  • Plugin config

Expected Behavior

When I go into a polygon geofence I should receive geofence: DWELL

Actual Behavior

I do receive geofence: DWELL for my radius geofences.

For polygon Geofences it only detecs enter / exit.

Steps to Reproduce

  1. add a polygon geofence
  2. walk in it
  3. I'm using debug mode with no license in expo.

sirusbaladi avatar Aug 21 '24 00:08 sirusbaladi

DWELL / loiteringDelay

It’s not implemented yet.

christocracy avatar Aug 21 '24 00:08 christocracy

DWELL / loiteringDelay

It’s not implemented yet.

Any timeline?

We are launching the app this saturday and I was convinced that polygon geofence had dwell. It's a core feature.

sirusbaladi avatar Aug 21 '24 00:08 sirusbaladi

Any timeline?

No. This winter perhaps.

christocracy avatar Aug 21 '24 00:08 christocracy

You’re free to run your own timers in the onGeofence enter event.

christocracy avatar Aug 21 '24 00:08 christocracy

You’re free to run your own timers in the onGeofence enter event.

Would you say something like this will work? In the if statement with event.vertices to make it happen only for polygon geofences.

I wonder if an 8 minutes times is okay.

BackgroundGeolocation.onGeofence((event) => {
  if (event.action === "ENTER" && event.vertices) {
    BackgroundGeolocation.startBackgroundTask().then((taskId) => {
      setTimeout(() => {
        console.log("DWELL");
        BackgroundGeolocation.stopBackgroundTask(taskId);
      }, 8 * 60 * 1000); // 8 minutes in milliseconds
    }).catch((error) => {
      console.error("Error starting background task:", error);
    });
  }
});

sirusbaladi avatar Aug 21 '24 00:08 sirusbaladi

or do you have a better way while waiting for the proper plugin implementation?

sirusbaladi avatar Aug 21 '24 00:08 sirusbaladi

You should keep a reference to your timerId so you can cancel it if EXIT occurs before timer expires. You’d need to keep a Hash of timers keyed on geofence.identifier.

8 min is kind of long.

const timerId = setTimeout(…)
DWELL_TIMERS[identifer] = timerId

christocracy avatar Aug 21 '24 00:08 christocracy

I see, thank you.

But I wonder if this will work at all. In the documentation it says that startBackgroundTask() will only work for 180 seconds and my timer is 8 minutes.

For non polygon geofences setting loiteringDelay to 8 minutes works great and never failed but I suspect it uses a different mechanism

sirusbaladi avatar Aug 21 '24 18:08 sirusbaladi

When the plug-in enters the containing geofence of a polygon, it turns ON location-services.

when location-services are ON, your app is completely alive in the background, just as if it were in the foreground.

there’s no need for background-tasks.

christocracy avatar Aug 21 '24 22:08 christocracy

When the plug-in enters the containing geofence of a polygon, it turns ON location-services.

when location-services are ON, your app is completely alive in the background, just as if it were in the foreground.

there’s no need for background-tasks.

even if .startGefence?

sirusbaladi avatar Aug 23 '24 22:08 sirusbaladi

even if .startGefence?

Yes. But since I've been working on polygon-geofencing for the last week+, I've decided to implement notifyOnDwell for polygon geofences.

christocracy avatar Aug 27 '24 22:08 christocracy

even if .startGefence?

Yes. But since I've been working on polygon-geofencing for the last week+, I've decided to implement notifyOnDwell for polygon geofences.

oh awesome! and is this already released? how to get it?

sirusbaladi avatar Aug 27 '24 22:08 sirusbaladi

I’ll let you know when it’s pushed to the private repo.

christocracy avatar Aug 27 '24 22:08 christocracy

See #2113 (this comment)

christocracy avatar Aug 28 '24 13:08 christocracy

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

github-actions[bot] avatar Sep 28 '24 02:09 github-actions[bot]

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

github-actions[bot] avatar Oct 13 '24 02:10 github-actions[bot]