点击这段代码,我可以获得gps数据和检索地址都可以在后台很好地工作,在大约20分钟后,应用程序停止做我的方面。我尝试了电池优惠和其他可能的事情,我尝试了后台服务。但在漫长的时间过后,似乎没有任何东西可以在后台获得位置。任何建议。
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;
});
});发布于 2020-02-12 00:08:07
您可以使用https://ionicframework.com/docs/native/background-mode
它只需修改应用程序的睡眠模式,使其在后台工作(而不会终止进程)。
如果进程被终止,那么应用程序可能会停止发送数据。
然后你可以让"cordova.plugins.backgroundMode.excludeFromTaskList()";让它从任务列表中消失(Android 5.0+)
希望这能对您有所帮助:)
https://stackoverflow.com/questions/60171180
复制相似问题