【问题标题】:ionic background geolocation stop working离子背景地理定位停止工作
【发布时间】:2020-02-11 14:30:26
【问题描述】:

有了这段代码,我可以获取 gps 数据并检索地址,所有这些都可以在后台正常工作,在几分钟内,大约 20 分钟后,应用程序 semms 停止做我想做的事情。 我尝试了电池特许权和其他可能的事情,我尝试了背景服务。 但是在很长一段时间之后,在后台获得位置似乎没有任何作用。 任何建议。

this.backgroundGeolocation.configure(config).then(() => {


console.log('backgroundGeolocation configconfigconfigconfigconfigconfig');

this.backgroundGeolocation.on(BackgroundGeolocationEvents.location).subscribe((location: BackgroundGeolocationResponse) => {

    console.log(location);  
    this.ngZone.run(() => {


        this.geolocationService.nativeGeocoder.reverseGeocode(location.latitude, 
        location.longitude).then((result: NativeGeocoderResult[]) =>{

      console.log("JSON.stringify(result[0]",JSON.stringify(result[0]));
            this.comunenoreplace = result[0]['locality'];
            this.comune = result[0]['locality'].replace(/[^A-Z0-9]+/ig, "-");
            this.provincia = result[0]['subAdministrativeArea'].replace(new RegExp('Città Metropolitana di|Provincia di', 'g'), '');
            this.globalLatitude = location.latitude;
            this.globalLongitude = location.longitude;


          }).catch((error: any) => console.log("reverseGeocode", error));


    });
    // 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 operations are successful or not.
    // IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
   // this.backgroundGeolocation.finish;
  });
});

【问题讨论】:

    标签: ionic-framework ionic4 tracking android-gps


    【解决方案1】:

    您可以使用https://ionicframework.com/docs/native/background-mode

    它只是修改应用程序的睡眠模式,使其在后台工作(不终止进程)。

    如果进程被杀死,那么应用程序可能会停止发送数据。

    然后你有 "cordova.plugins.backgroundMode.excludeFromTaskList()";使其从任务列表中消失(Android 5.0+)

    希望得到帮助:)

    【讨论】:

      猜你喜欢
      • 2016-12-23
      • 1970-01-01
      • 2018-05-03
      • 2020-08-29
      • 1970-01-01
      • 2015-04-23
      • 1970-01-01
      • 2021-10-11
      • 1970-01-01
      相关资源
      最近更新 更多