http request fail in background mode
ikkettuvvoi opened this issue · 4 comments
ikkettuvvoi commented
I connected the plugin to my application in Ionic 6.
I noticed that the locations on my web server are not arriving in the background after a few minutes.
By doing a thorough investigation I have agreed that the position is processed correctly in the backgound but the HTTP (POST) call is no longer performed
To Reproduce
async configureBackgroundGeolocation() {
const uuid = await Device.getId();
BackgroundGeolocation.addWatcher(
{
backgroundMessage: "Track attivo in background",
backgroundTitle: "Track attivo.",
requestPermissions: true,
stale: false,
distanceFilter: 1
},
(location, error) => {
if (error) {
if (error.code === "NOT_AUTHORIZED") {
if (window.confirm(
"This app needs your location, " +
"but does not have permission.\n\n" +
"Open settings now?"
)) {
BackgroundGeolocation.openSettings();
}
}
return console.error(error);
}
console.log('gillo gps: ', location);
try {
let url = environment.api + "/mappa/gps";
this.http.post(url, { debug: 0, location: location, seriale: uuid }).subscribe((res: any) => {
console.log('gillo post gps', res);
},
(error) => {
console.log("gillo error (**) ", error)
});
} catch (err) {
console.log("gillo error (*) ", err)
}
return location;
}
).then(function after_the_watcher_has_been_added(watcher_id) {
});
}
- Device: Oppo
- OS: Android 11
ikkettuvvoi commented
I apologize, I forgot in a hurry to say thank you.
diachedelic commented
See #14.
diachedelic commented
In short, you must use Capacitor's HTTP plugin to send HTTP requests in the background.
ikkettuvvoi commented
perfect! thanks!