首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >离子背景地理定位停止工作

离子背景地理定位停止工作
EN

Stack Overflow用户
提问于 2020-02-11 22:30:27
回答 1查看 906关注 0票数 0

点击这段代码,我可以获得gps数据和检索地址都可以在后台很好地工作,在大约20分钟后,应用程序停止做我的方面。我尝试了电池优惠和其他可能的事情,我尝试了后台服务。但在漫长的时间过后,似乎没有任何东西可以在后台获得位置。任何建议。

代码语言:javascript
复制
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;
  });
});
EN

回答 1

Stack Overflow用户

发布于 2020-02-12 00:08:07

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

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

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

然后你可以让"cordova.plugins.backgroundMode.excludeFromTaskList()";让它从任务列表中消失(Android 5.0+)

希望这能对您有所帮助:)

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60171180

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档