我有一个IONIC2应用程序,它需要每天早上8点起床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();
}发布于 2017-05-09 09:12:16
我不使用这个插件,但有相同的症状。我不知道到底出了什么问题:没有错误信息,没有线索,但几个小时后,应用程序一直关闭。
我想在安装和卸载如此多的cordova插件后出现了一些问题。现在这个应用程序更稳定了。我移除并增加了平台。这似乎能胜任这份工作。
发布于 2017-05-25 15:44:45
我一直在阅读关于ionic2和性能的文章。在这么多的原因中,低性能和崩溃的可能性与不订阅可观测数据有关。阅读有关组件被破坏时的异步管道和.unsubscribe可观测性的信息,ngOnDestroy
我发现的另一个问题是一个在角度上发展的非常基本的错误。我在应用模块中加载了所有内容,因此这需要大量内存来同时加载整个应用程序。我猜慢的终端机会影响更多。无论如何,作为.module文件的基本角度概念应该被理解。
https://stackoverflow.com/questions/41722579
复制相似问题