Closed pdrhlik closed 3 years ago
The notification certainly should disappear – are you absolutely sure that all watchers have been removed at that point? Do you retain the id
from addWatcher
for later use with removeWatcher
?
On 1 Feb 2021, at 6:38 am, Patrik Drhlik notifications@github.com wrote:
I start by calling addWatcher() and then after some time I decide to remove it by calling removeWatcher(). My understanding would be that the sticky notification would disappear when there is no active watcher. No watcher means no location tracking and that should be no notification, is that right?
I have a special option inside my app settings that allows users to switch background geolocation on/off. The idea was to remove the watcher when app is being backgrounded and then start it again when it's foregrounded.
The sample approach and logic I tried is something like this. I'm using Capacitor's App plugin to detect if the app was backgrounded or foregrounded.
App.addListener("appStateChange", state => { if (!this.canUseBackgroundGps) { if (state.isActive) { BackgroundGeolocation.addWatcher(/ ... /); } else { BackgroundGeolocation.removeWatcher(/ ... /); } } }); I only tested and observed this behaviour on Android. I'll test if it behaves the same on iOS tomorrow.
Thanks for any heads up, Patrik
— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/capacitor-community/background-geolocation/issues/4, or unsubscribe https://github.com/notifications/unsubscribe-auth/AACLZQGWZUHV7ZUEACFW56TS4XBETANCNFSM4W3W5GZA.
Note that on iOS, there is no notification.
The notification certainly should disappear – are you absolutely sure that all watchers have been removed at that point? Do you retain the
id
fromaddWatcher
for later use withremoveWatcher
?
The problem was that I thought addWatcher()
was returning the watcher ID as a Promise
. It works as expected in 0.3.8 anticipating a string instead.
Thanks.
I am puzzled by this same issue. I'm calling
this.watchId = BackgroundGeolocation.addWatcher({
/* options, callback */
});
and later
BackgroundGeolocation.removeWatcher({ id: this.watchId });
But the notification sticks? Is that not the right approach?
The addWatcher
function does not return an ID, it returns a Promise which resolves to an ID.
Any suggest
I start by calling
addWatcher()
and then after some time I decide to remove it by callingremoveWatcher()
. My understanding would be that the sticky notification would disappear when there is no active watcher. No watcher means no location tracking and that should be no notification, is that right?I have a special option inside my app settings that allows users to switch background geolocation on/off. The idea was to remove the watcher when app is being backgrounded and then start it again when it's foregrounded.
The sample approach and logic I tried is something like this. I'm using Capacitor's App plugin to detect if the app was backgrounded or foregrounded.
I only tested and observed this behaviour on Android. I'll test if it behaves the same on iOS tomorrow.
Thanks for any heads up, Patrik