繁体   English   中英

IONIC2-即使使用背景地理定位,应用也会在一段时间后被杀死

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM