The geographical position of the background mode of Cordoba iOS 10

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, //10m accurate
    stationaryRadius: 5, // if stationary, device must move beyond 5m to engage background-tracking
    distanceFilter: 5, //min distance a device must move before update event is generated
    stopOnTerminate: true, // <-- enable this to clear background location settings when the app terminates
    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, ..

- , .

+4
1

ios10 .

info.plist:

<key>NSMotionUsageDescription</key> <string>The app uses accelerometer to increase battery efficiency by intelligently toggling location-tracking</string>

-1

Source: https://habr.com/ru/post/1658446/


All Articles