In my cordova project, I use a combination of Katzer plugins cordova-plugin-background-mode and Mauron85 background-geolocation plug-ins to enable background location tracking. Both plugins are the latest stable release.
This works fine on Android and ios 8, 9. But now with the release of ios 10 we are having a problem. I did some tests and it seems that the background plugin is not constantly updating the mode (background or foreground) to the correct position. This makes our application very buggy.
The code we use to turn on / off the background mode is as follows:
function enableBackgroundMode() {
if ($rootScope.ionicReady && window.cordova && !cordova.plugins.backgroundMode.isEnabled()) {
cordova.plugins.backgroundMode.enable();
}
}
function disableBackgroundMode() {
if ($rootScope.ionicReady && window.cordova && cordova.plugins.backgroundMode.isEnabled()) {
cordova.plugins.backgroundMode.disable();
}
}
function isRunningInBackground() {
return $rootScope.ionicReady && window.cordova && cordova.plugins.backgroundMode.isActive();
}
isRunningInBackground() true, , .
function getCurrentLocationInBackground(interval) {
var deferred = $q.defer();
backgroundGeolocation.configure((location) => {
backgroundGeolocation.finish();
LogService.debug("Latitude: " + location.latitude + ", Longitude: " + location.longitude);
deferred.resolve(location);
}, (error) => {
LogService.error('BackgroundGeoLocation error');
deferred.reject(error);
}, {
desiredAccuracy: 10,
stationaryRadius: 5,
distanceFilter: 5,
stopOnTerminate: true,
notificationTitle: translations['generic.background.tracking.title'],
notificationText: translations['generic.background.tracking.text'],
locationProvider: backgroundGeolocation.provider.ANDROID_ACTIVITY_PROVIDER,
activityType: "AutomotiveNavigation",
interval: interval ? parseInt(interval) : 30000
});
if (window.cordova) {
backgroundGeolocation.start();
}
return deferred.promise;
}
, ios 10, , , cordova.plugins.backgroundMode.isActive() true, ..
- , .