I'm using Ionic 3 and this cordova plugin mauron85/cordova-plugin-background-geolocation but the app doesn't stream coordinates when it's in the background in iOS.
It works in Android, iOS emulator but not in a real iPhone. Also, the url option stops streaming after 1s
My code so far:
/**
*
* @param {boolean} status
* @param {number} stepOn
*/
private registerCoords(status: boolean, stepOn?: number): void {
let step: number = stepOn ? stepOn : 1;
if (!STATIC.GEO_INTERVAL && status) {
STATIC.GEO_INTERVAL = setInterval((() => {
this.currentCoords = this.geolocationService.getCoords();
if (!this.isNetWork) {
this.functions.f_alertToast('Network connection lost', 0);
return this.registerCoords(false);
}
if (!this.currentCoords && !this.isProcessPicture) {
this.geoLocationEvent = false;
this.isGeoLocation = false;
console.warn('[HomePage] registerCoords() -> setInterval() [GPS connection lost!!]');
}
else if (this.currentCoords) {
this.geoLocationEvent = true;
this.isGeoLocation = true;
}
this.saveCoords(this.currentCoords, step);
step = 1;
}).bind(this), STATIC.GEO_TIMEOUT);
this.finishLoad();
}
if (status === false) {
clearInterval(STATIC.GEO_INTERVAL);
STATIC.GEO_INTERVAL = null;
this.checkGeolocation();
}
}
config.xml
<plugin name="cordova-plugin-mauron85-background-geolocation" spec="2.3.5">
<variable name="ICON" value="@mipmap/icon" />
<variable name="SMALL_ICON" value="@mipmap/icon" />
<variable name="ACCOUNT_NAME" value="@string/app_name" />
<variable name="ACCOUNT_LABEL" value="@string/app_name" />
<variable name="ACCOUNT_TYPE" value="$PACKAGE_NAME.account" />
<variable name="CONTENT_AUTHORITY" value="$PACKAGE_NAME" />
<variable name="GOOGLE_PLAY_SERVICES_VERSION" value="11+" />
<variable name="ANDROID_SUPPORT_LIBRARY_VERSION" value="23+" />
</plugin>
<plugin name="cordova-plugin-geolocation" spec="2.4.3">
<variable name="GEOLOCATION_USAGE_DESCRIPTION" value="..." />
</plugin>
package.json
"@ionic-native/geolocation": "4.9.0",
"cordova-plugin-geolocation": "2.4.3",
"cordova-plugin-mauron85-background-geolocation": "2.3.5",
from Ionic3 in iOS can't stream coordinates to my API when the app is in the background
No comments:
Post a Comment