简体   繁体   English

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

[英]IONIC2 - app gets killed after some time even when using Background Geolocation

I have an IONIC2 app, which needs to wake up every morning at 8 AM for 20 minutes to send user reminders based on the user's geolocation. 我有一个IONIC2应用程序,该应用程序需要每天早晨8 AM醒来20分钟,以便根据用户的地理位置发送用户提醒。

I am using this plugin (which uses IOS significant changes API to monitor changes in user's location) https://github.com/mauron85/cordova-plugin-background-geolocation 我正在使用此插件(它使用IOS重大更改API来监视用户位置的更改) https://github.com/mauron85/cordova-plugin-background-geolocation

The problem: The app doesn't get killed when I close the app and the background geolocation works for me fine for some time. 问题:当我关闭应用程序时,该应用程序不会被杀死,并且后台地理位置对我来说可以正常工作一段时间。 I have tested upto an hour. 我已经测试了一个小时。 But when I wake up next morning, I find the app was killed by IOS. 但是第二天早上醒来时,我发现该应用程序被IOS杀死了。

I know there is another plugin to keep the app running in the background https://github.com/katzer/cordova-plugin-background-mode , but I have read tons of complaints from people that it will cause your app to be rejected by the AppStore (In fact, the plugin has a disclaimer to the same effect too). 我知道还有另一个插件可以使应用程序在后台运行https://github.com/katzer/cordova-plugin-background-mode ,但是我读到很多人抱怨它会导致您的应用程序被拒绝由AppStore提供(实际上,该插件也具有相同效果的免责声明)。

For waking up the app tomorrow, I simply set a setTimeout 为了明天唤醒应用程序,我只需设置一个setTimeout

setTimeout(function(){
      console.log('waking up');
      self.helper.scheduleLocalNotification('Hello World', 'Good Morning', 10, "");
      self.ionViewDidEnter();
    }, wakeupinMilliSeconds);

Here is my geolocation code: 这是我的地理位置代码:

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();    
      }

I don't use this plugin but had same symptons. 我不使用此插件,但有相同的症状。 I couldn't figure out what was wrong: no error messages, no clues but app kept closing after a few hours. 我不知道出了什么问题:没有错误消息,没有任何线索,但是应用程序在几个小时后一直关闭。

I guess there was something messed up after installing and uninstalling so many cordova plugins. 我猜想在安装和卸载了这么多的cordova插件后,事情变得有些混乱。 Now the app is much more stable. 现在,该应用程序更加稳定。 I removed and added platform. 我删除并添加了平台。 That seemed to do the job. 那似乎完成了工作。

I've been reading about ionic2 and performance. 我一直在阅读有关ionic2和性能的信息。 Among so many reasons, a possibility about low performance and crash is related not to unsubscribe from observables. 在众多原因中,有关性能低下和崩溃的可能性与不要取消可观察对象有关。 Read about async pipe and .unsubscribe observables when component is destroyed ngOnDestroy 阅读有关组件销毁时的异步管道和.unsubscribe observables的信息ngOnDestroy

Another problem i found was a very basic mistake developing in angular. 我发现的另一个问题是在角度方面出现了一个非常基本的错误。 I loaded everything in the app module so this required lot of memory to load the entire app at once. 我将所有内容都加载到了应用模块中,因此这需要大量内存才能立即加载整个应用。 I guess with slow terminals that can affect more. 我猜想慢速的终端可能会影响更多。 Anyway, basic angular concepts as .module files should be understood. 无论如何,应该了解基本的角度概念(例如.module文件)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 即使应用程序被杀死,flutter_background_geolocation 也会获取位置吗? - Does flutter_background_geolocation fetch the location even when app is killed? 即使应用被杀后如何接收内容? - How to receive content even after app gets killed? 获取iOS应用在后台甚至被杀的位置 - Getting location for an iOS app when it is in the background and even killed IONIC 2-每当应用打开时,地理位置请求或许可 - IONIC 2 - GeoLocation ask or permission every time when app open 即使应用程序被杀死也监视通话 - Monitoring calls even if the app gets killed 应用在一段时间后被IOS终止 - App gets terminated by IOS after some time 一段时间后在后台重置iOS应用程序 - Reset iOS app in background after some time iOS-在设备设置中,如果我更改时间,即使在应用程序后台,终止状态下也应得到通知 - iOS - in device settings if i change time it should get notified even in app background, killed state Ionic / Cordova:即使在后台,如何强制应用在启动时刷新? - Ionic / Cordova: How to force app to refresh on start, even when it was in background? 即使应用在iOS中被杀死或从后台删除,我如何继续更新我的位置? - How Can I Continue updating my location even when app is killed or removed from background in ios?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM