transistorsoft / capacitor-background-geolocation

The most sophisticated background location-tracking & geofencing module with battery-conscious motion-detection intelligence for iOS and Android.
MIT License
95 stars 16 forks source link

Background geolocation is used all the time #273

Closed suyundukov closed 1 month ago

suyundukov commented 1 month ago

Your Environment

Expected Behaviour

App uses background location only when needed.

Actual Behaviour

App uses background location all the time.

Steps to Reproduce

  1. https://github.com/suyundukov/capacitor-background-geolocation-issue-reproduction
  2. Install app
  3. Add some point
  4. In 3-4 days I'm receiving this notification:

Context

I'm working with geofences and I want to show a notification whenever user is in geofence point. This is how I use it:

BackgroundGeolocation.onGeofence((_, taskId) => {
  LocalNotifications.schedule(...);
  BackgroundGeolocation.finish(taskId);
});

await BackgroundGeolocation.ready({
  backgroundPermissionRationale: { title, message, positiveAction, negativeAction },
  disableLocationAuthorizationAlert: true,
  startOnBoot: true,
  stopOnTerminate: false,
});

BackgroundGeolocation.startGeofences();

It works most of the time, but my biggest problem is that app is using background location all the time. I thought it will use it only when user is near geofence point.

christocracy commented 1 month ago

I thought it will use it only when user is near geofence point.

Your assumption was incorrect. Geofences are managed purely by the OS. How do you think the OS knows when the device is near a geofence: by periodically sampling the location.

the user will get that dialog once for the life of the app install. There’s no way to avoid it.

suyundukov commented 1 month ago

I was under the impression that geofences were managed by the operating system once the app set them up.

The app would specify the geofence's parameters and what to do when it's crossed, while the OS would take care of tracking the location and notify the app when needed, even if the app wasn't active.

However, it seems like the app is continuously tracking the location in the background, or am I mistaken?

christocracy commented 1 month ago

But by the way it looks, app is constantly monitoring location in background or am I wrong on this one?

You are wrong. Your app is constantly monitoring location only if a solid location arrow is shown in the OS status bar.

see your device Settings Privacy and Security for more info:

IMG_2057

suyundukov commented 1 month ago

If I’ve only set up a single geofence point, why is it showing that the app has accessed my location at multiple places?

christocracy commented 1 month ago

How do you think the OS knows where you’re at so it can evaluate a geofence to ask “am I in this geofence?”

suyundukov commented 1 month ago

Isn't it the OS, rather than the app itself, that utilises location services in that case?

christocracy commented 1 month ago

What does your privacy settings show for your app?

suyundukov commented 1 month ago

What does your privacy settings show for your app?

Allow Location Access: "Always".

Isn't it the OS, rather than the app itself, that utilises location services in that case?

According to Apple’s documentation, "the system monitors regions and wakes up your app as needed when conditions change between satisfied and unsatisfied states". Given this, why does it indicate that my app is using geolocation even when user is in a different country from the original geofence location?

suyundukov commented 1 month ago

After further investigation, I realized that the issue was actually on my side, and not related to the project. I apologize for the oversight and any confusion this may have caused. I'll be closing this issue now. Thank you for your understanding.