OGeek|极客世界-中国程序员成长平台

标题: ios - IONIC2 - 即使使用后台地理位置,应用程序也会在一段时间后被杀死 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 18:37
标题: ios - IONIC2 - 即使使用后台地理位置,应用程序也会在一段时间后被杀死

我有一个 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();    
      }



Best Answer-推荐答案


我没有使用这个插件,但有相同的症状。我不知道出了什么问题:没有错误消息,没有线索,但应用程序在几个小时后一直关闭。

我猜在安装和卸载这么多 Cordova 插件后出现了一些问题。现在该应用程序更加稳定。我删除并添加了平台。这似乎完成了这项工作。

关于ios - IONIC2 - 即使使用后台地理位置,应用程序也会在一段时间后被杀死,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41722579/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4