[英]Does flutter_background_geolocation fetch the location even when app is killed?
[英]IONIC2 - app gets killed after some time even when using Background Geolocation
我有一個IONIC2應用程序,該應用程序需要每天早晨8 AM醒來20分鍾,以便根據用戶的地理位置發送用戶提醒。
我正在使用此插件(它使用IOS重大更改API來監視用戶位置的更改) https://github.com/mauron85/cordova-plugin-background-geolocation
問題:當我關閉應用程序時,該應用程序不會被殺死,並且后台地理位置對我來說可以正常工作一段時間。 我已經測試了一個小時。 但是第二天早上醒來時,我發現該應用程序被IOS殺死了。
我知道還有另一個插件可以使應用程序在后台運行https://github.com/katzer/cordova-plugin-background-mode ,但是我讀到很多人抱怨它會導致您的應用程序被拒絕由AppStore提供(實際上,該插件也具有相同效果的免責聲明)。
為了明天喚醒應用程序,我只需設置一個setTimeout
setTimeout(function(){
console.log('waking up');
self.helper.scheduleLocalNotification('Hello World', 'Good Morning', 10, "");
self.ionViewDidEnter();
}, wakeupinMilliSeconds);
這是我的地理位置代碼:
setupBackGroundGeolocation(){
let config = {
desiredAccuracy: 100,
stationaryRadius: 50,
distanceFilter: 100,
interval: 5000,
pauseLocationUpdates: false,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
BackgroundGeolocation.configure((location) => {
console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
this.currentLocation.lat = location.latitude;
this.currentLocation.lng = location.longitude;
Promise.all([
//I do some calculations here.
]).then(d => {
// 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.
BackgroundGeolocation.finish(); // FOR IOS ONLY
});
}, (error) => {
console.log('BackgroundGeolocation error');
}, config);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
BackgroundGeolocation.start();
}
我不使用此插件,但有相同的症狀。 我不知道出了什么問題:沒有錯誤消息,沒有任何線索,但是應用程序在幾個小時后一直關閉。
我猜想在安裝和卸載了這么多的cordova插件后,事情變得有些混亂。 現在,該應用程序更加穩定。 我刪除並添加了平台。 那似乎完成了工作。
我一直在閱讀有關ionic2和性能的信息。 在眾多原因中,有關性能低下和崩潰的可能性與不要取消可觀察對象有關。 閱讀有關組件銷毀時的異步管道和.unsubscribe observables的信息ngOnDestroy
我發現的另一個問題是在角度方面出現了一個非常基本的錯誤。 我將所有內容都加載到了應用模塊中,因此這需要大量內存才能立即加載整個應用。 我猜想慢速的終端可能會影響更多。 無論如何,應該了解基本的角度概念(例如.module文件)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.