Closed josiahbryan closed 2 years ago
You are probably adding multiple onLocation
event-listeners.
See API docs Subscription
Are those not automatically removed when stopping the background plugin? Do we have to remove all listeners when calling stop?
remove all listeners when calling stop?
The plugin doesnβt emit events when stopped.
every time you call onLocation, a new listener is created.
Are those not automatically removed when stopping the background plugin?
no. When you turn off your stereo, music stops playing from the speakers. The speaker wires donβt get disconnected. Every time you call onLocation, itβs like wiring up a new speaker to your stereo system.
@christocracy something's wrong - I'm getting undefined
as the return onLocation
:
const subscription = BackgroundGeolocation.onLocation(location => {
console.log("[onLocation] ", location);
});
console.log(`trackSubscription`, subscription);
(3x instances of the message because I start/stop the plugin in response to user enabling/disabling "tracking" at various points in the UI)
I thought it might be plugin version, but I updated to the latest plugin (4.4.3
) and no change - still get undefined
- how am I supposed to stop listening to subscriptions if I don't get a subscription? :-D haha!
Suggestions...?
You probably didn't npx cap sync
after installing.
Hmm...well, my postinstall
script does do npx cap sync
, but I suppose something didn't sync right because a few hours later (now) after doing npx cap sync
again, it suddenly shows a proper return value. All good now. Thanks.
Your Environment
npx cap doctor
)Latest Dependencies:
@capacitor/cli: 3.3.3 @capacitor/core: 3.3.3 @capacitor/android: 3.3.3 @capacitor/ios: 3.3.3
Installed Dependencies:
@capacitor/cli: 3.1.2 @capacitor/core: 3.1.2 @capacitor/android: 3.1.2 @capacitor/ios: 3.1.2
[success] iOS looking great! π [success] Android looking great! π
Expected Behavior
One
onLocation
event per UUID (unless previous onLocation for same UUID threw an Error)Actual Behavior
Hundreds of
onLocation
events per UUIDSteps to Reproduce
Note: I've only seen this in production / "in the wild" - cannot reproduce locally or in dev.
This screenshot shows console logs captured via LogRocket. Happy to provide access to LogRocket sessions showing this issue:
These onLocation events are foreground events, NOT background iOS events. They are being captured and logged by the following code (sanatized):
Context
Track drivers
Debug logs
Logs not available from production devices
Logs
``` PASTE_YOUR_LOGS_HERE ```