菜鸟教程小白 发表于 2022-12-11 18:37:22

ios - IONIC2 - 即使使用后台地理位置,应用程序也会在一段时间后被杀死


                                            <p><p>我有一个 IONIC2 应用,它需要每天早上 8 点醒来 20 分钟,以根据用户的地理位置向用户发送提醒。 </p>

<p>我正在使用这个插件(它使用 IOS 重大变化 API 来监控用户位置的变化)
<a href="https://github.com/mauron85/cordova-plugin-background-geolocation" rel="noreferrer noopener nofollow">https://github.com/mauron85/cordova-plugin-background-geolocation</a> </p>

<p><strong>问题:</strong>
当我关闭应用程序时,该应用程序不会被杀死,并且后台地理位置对我来说可以正常工作一段时间。我已经测试了一个小时。但是当我第二天早上醒来时,我发现这个应用程序被 IOS 杀死了。 </p>

<p>我知道还有另一个插件可以让应用程序在后台运行 <a href="https://github.com/katzer/cordova-plugin-background-mode" rel="noreferrer noopener nofollow">https://github.com/katzer/cordova-plugin-background-mode</a> ,但我读过很多人提示它会导致你的应用被 AppStore 拒绝(事实上,该插件也有同样效果的免责声明)。 </p>

<p>为了明天唤醒应用程序,我只需设置一个 setTimeout</p>

<pre><code>setTimeout(function(){
      console.log(&#39;waking up&#39;);
      self.helper.scheduleLocalNotification(&#39;Hello World&#39;, &#39;Good Morning&#39;, 10, &#34;&#34;);
      self.ionViewDidEnter();
    }, wakeupinMilliSeconds);
</code></pre>

<p>这是我的地理位置代码:</p>

<pre><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) =&gt; {
            console.log(&#39; BackgroundGeolocation callback:&#39; + location.latitude + &#39;,&#39; + location.longitude);
            this.currentLocation.lat = location.latitude;
            this.currentLocation.lng = location.longitude;

            Promise.all([
                   //I do some calculations here.
            ]).then(d =&gt; {
                // IMPORTANT:You must execute the finish method here to inform the native plugin that you&#39;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&#39;T, ios will CRASH YOUR APP for spending too much time in the background.
                BackgroundGeolocation.finish(); // FOR IOS ONLY
            });
      }, (error) =&gt; {
          console.log(&#39;BackgroundGeolocation error&#39;);
      }, config);

      // Turn ON the background-geolocation system.The user will be tracked whenever they suspend the app.
      BackgroundGeolocation.start();   
      }
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>我没有使用这个插件,但有相同的症状。我不知道出了什么问题:没有错误消息,没有线索,但应用程序在几个小时后一直关闭。</p>

<p>我猜在安装和卸载这么多 Cordova 插件后出现了一些问题。现在该应用程序更加稳定。我删除并添加了平台。这似乎完成了这项工作。</p></p>
                                   
                                                <p style="font-size: 20px;">关于ios - IONIC2 - 即使使用后台地理位置,应用程序也会在一段时间后被杀死,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/41722579/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/41722579/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - IONIC2 - 即使使用后台地理位置,应用程序也会在一段时间后被杀死