Closed barart closed 6 months ago
If you're trying to do an http request in the plugin's event-handlers, you're likely experiencing the Capacitor webview failing to execute code in the background.
I suggest you take advantage of the plugin's built-in native HTTP service. See the API docs HTTP Guide for more information.
Hello Chris... im not trying to make a http request, im trying to call an api as you can se on my code:
BackgroundGeolocation.onMotionChange((location) => {
console.log('[onMotionChange]', location);
console.log('Update Coords');
const param = {
lat: location.location.coords.latitude,
lng: location.location.coords.longitude,
}
this.api.updateCoords(param).then((data) => {
console.log(data);
}).catch(error => {
console.log(error);
});
});
as i wrote above, this works on ios but not on android
im not trying to make a http request, im trying to call an api as you can se on my code:
Yes, it looks like you're trying to manage sending location data to your API, likely via HTTP request, via Javascript code.
Are you observing the plugin logs? See Wiki Debugging.
Yes, as i mentioned when opening the thread, i already observed the plugin logs, there is nothing relevant or errors compared to the log with the app in foreground and the log in background, seems very similar both of them
I suggest you print log messages in your event callbacks using BackgroundGeolocation.logger
. Those will print messages to the plugin's logs, which can be captured with getLog
/ emailLog
. That will tell you if the event-handlers are actually running.
Im still debugging this, the BackgroundGeolocation.logger
has been helpful, however, everything seems to work (without any code changes) as same and logger show that it "execute" my code (but it doesn't do what it should); what is strange for me, is that my code seems to start working completely when i added the BackgroundGeolocation.logger
into it :/
Im still investiganting...
iOS works exactly as expected, pure beauty
Hello,
I have the exact same problem. @barart did you find a solution for this?
Thank you in advance
Hello,
I have the exact same problem. @barart did you find a solution for this? @christocracy
Thank you in advance
Hello @ramandeepR,
I found a solution for this problem. Android will run the code only if it was written in Java. You must write this code in Java if you wont to do something in background. More about this you can find here: https://github.com/transistorsoft/cordova-background-geolocation-lt/wiki/Android-Headless-Mode#step-2a--plugin-version-2132
Best regards, Mitar
Hello @mitar096
Thank you for reply. Can you help me with this integration? I am stuck on this issue now. May be I need to stop this only due to background location not working accurately.
Best Regards, Ramandeep
Hello @christocracy I am encountering a similar problem where I need to transmit certain events (onMotionChange, onProviderChange) to my backend server. While the app is active in the background or foreground, the listeners successfully send these events. However, when the app is forcibly closed, I require immediate reception of these events on my server.
I am using plugin inbuild HTTP service to send the locations in the background and killed state. But that service only sends locations events for the IOS. they are not sending providerChange event in the background for ios
Platform: Android
“they are not sending providerChange event in the background for ios”
This issue thread was posted related to Android.
@christocracy Is it necessary to handle the events in the killed state by writing native code for both Android and iOS platforms by myself?
Is there any potential for the plugin to send all providerChange events to my specified config URL via HTTP, similar to how it sends location updates when the app is in a killed state?
Could you please incorporate this configuration into the plugin so that it can send the events using a single config? Since the native code is already implemented in the plugin, this addition would be beneficial.
Is it necessary to handle the events in the killed state by writing native code for both Android and iOS platforms by myself?
Only Android. iOS has no concept of “headless”.
Is there any potential for the plugin to send all providerChange events to my specified config URL via HTTP
Android already does. For iOS, you must do so manually. iOS won’t fire the onProviderChange event if your app is terminated.
@christocracy Could you please provide further clarification on what you mean by "manually handling the event" in the context of iOS?
My objective is to ensure that every onProviderChange event from the iOS app is sent to my server, regardless of the app's status (foreground, background, or killed state). This way, I can keep track of whether the user has granted or revoked location permissions.
For instance, if the user initially grants permission and tracking begins, but later manually revokes the location permission from the app through device settings, I would like to update my server accordingly to indicate that the user has selected incorrect permissions.
My objective is to ensure that every onProviderChange event from the iOS app is sent to my server, regardless of the app's status (foreground, background, or killed state)
On iOS, you can’t.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.
Your Environment
npx cap doctor
) đź’Š Capacitor Doctor đź’ŠLatest Dependencies:
@capacitor/cli: 3.1.2 @capacitor/core: 3.1.2 @capacitor/android: 3.1.2 @capacitor/ios: 3.1.2
Installed Dependencies:
@capacitor/cli: 3.1.2 @capacitor/android: 3.1.2 @capacitor/core: 3.1.2 @capacitor/ios: 3.1.2
[success] iOS looking great! đź‘Ś [success] Android looking great! đź‘Ś
Plugin config provided to
#ready
:My onLocation and onMotionChange code:
Expected Behavior
When app is in background (closed/killed), plugin should be able to execute my code when onMotionChange and onLocation events; as i have debug mode enabled, i can hear when the plugin is registering movements, changes and locations, however my code is never executed, but if i have the app in foreground the plugin execute my code successfully on MotionChange and onLocation events, this only occurs on Android, on iOS works as expected.
Actual Behavior
When app is in background (closed/killed) plugin works as i can hear the debug sounds, but it never execute my code onMotionChange and onLocation events.
Steps to Reproduce
Context
Im trying to execute a code when onMotionChange and onLocationChange
Debug logs
Logs
``` I dont think logs are relevant in this case as the plugin works but it dont execute my code on background, there is no different on foreground and background logs. I could not find [onLocation] or [onMotionChange] strings on logs (foreground or background) ```