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('waking up');
self.helper.scheduleLocalNotification('Hello World', 'Good Morning', 10, "");
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) => {
console.log(' 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();
}
</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]