Ионная фоновая проблема геолокации - PullRequest
0 голосов
/ 14 ноября 2018

Я работаю над фоновым приложением Geolocation. Возникает проблема: когда приложение закрывается из фона, служба геолокации в фоновом режиме не работает. Я хочу, чтобы в случае удаления приложения из фона служба геолокации фона приложения работала.

Любая помощь?

Ответы [ 2 ]

0 голосов
/ 14 ноября 2018

Вы можете установить фоновый плагин геолокации

$ ионный плагин Cordova добавить Cordova-плагин-Mauron85-фон-геолокации $ npm install --save @ ionic-native / background-geolocation

0 голосов
/ 14 ноября 2018

Вы можете установить плагин фоновой геолокации

$ ionic cordova plugin add cordova-plugin-mauron85-background-geolocation
$ npm install --save @ionic-native/background-geolocation

, а также добавить его в .ts, например,

import { BackgroundGeolocation, BackgroundGeolocationConfig, BackgroundGeolocationResponse } from '@ionic-native/background-geolocation';

constructor(private backgroundGeolocation: BackgroundGeolocation) { }

...

const config: BackgroundGeolocationConfig = {
            desiredAccuracy: 10,
            stationaryRadius: 20,
            distanceFilter: 30,
            debug: true, //  enable this hear sounds for background-geolocation life-cycle.
            stopOnTerminate: false, // enable this to clear background location settings when the app terminates
    };

this.backgroundGeolocation.configure(config)
  .subscribe((location: BackgroundGeolocationResponse) => {

    console.log(location);

    // IMPORTANT:  You must execute the finish method here to inform the native plugin that you're finished,
    // and the background-task may be completed.  You must do this regardless if your HTTP request is successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
    this.backgroundGeolocation.finish(); // FOR IOS ONLY

  });

// start recording location
this.backgroundGeolocation.start();

// If you wish to turn OFF background-tracking, call the #stop method.
this.backgroundGeolocation.stop();

, для дальнейшей ссылки, пожалуйста, перейдите по этой ссылке

https://ionicframework.com/docs/native/background-geolocation/

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...