// Event-listeners return a Subscription instance, containing a .remove() method. constsubscription = BackgroundGeolocation.onLocation(location=> { console.log("[onLocation] ", location); }); . . . // Later, to remove the event-listener: subscription.remove();
One might typically manage a collection of Subscription instances
Example
importBackgroundGeolocation, { Location, Subscription } from ...
// Your custom Collection of Subscription instances. constSUBSCRIPTIONS = [];
// Your custom method to push a Subscription instance. constsubscribe = (subscription:Subscription) => { SUBSCRIPTIONS.push(subscription); }
// Your custom method to interate your SUBSCRIPTIONS and .remove each. constunsubscribe = () => { SUBSCRIPTIONS.forEach((subscription:Subscription) =>subscription.remove()); }
constinitBackgroundGeolocation = () { // Create event-listeners as usual, feeding the returned Subscription into // your custom subscribe() method. subscribe(BackgroundGeolocation.onLocation((location:Location) => { console.log('[onLocation]', location); });
Object returned by BackgroundGeolocation event-listeners.
Subscriptioncontains just a single method remove, used for removing an event-listener.Removing an event-listener:
Example
One might typically manage a collection of
SubscriptioninstancesExample