[英]If I have location services turned on then how can my app get killed when it enters background mode?
My app is getting killed when it's in the background. 我的应用程序在后台运行时被杀死。
However my app is constantly kept alive in the background for locationTracking purposes. 但是,出于位置跟踪的目的,我的应用始终在后台保持活动状态。
I've spoken to users who have experienced this issue and they're saying that their locationTracking is set to Always and they haven't turned it off. 我已经与遇到此问题的用户进行了交谈,他们说他们的locationTracking设置为“始终”并且尚未关闭。
I'm assuming that even though the app is in background (not suspended) still it can get flushed out of memory due to a memory warning. 我假设即使该应用程序在后台(未挂起),由于内存警告,它仍可能会刷新出内存。
My question other than memory is there any other reason? 我的问题除了记忆之外还有其他原因吗? I looked into Apple docs and see that it could be due to a +80% CPU for more than 1 minute in the background but that's not happening. 我查看了Apple文档,发现这可能是由于+ 80%的CPU在后台运行了1分钟以上,但这没有发生。 I know that crashes can also be a reason for the app to get launched again, but our crashes haven't increased. 我知道崩溃也可能是该应用再次启动的原因,但是我们的崩溃并没有增加。 We're not seeing any crashes in our locationManager class and the only thing we do in the background is track location and make an API call. 我们没有在locationManager类中看到任何崩溃,并且我们在后台所做的唯一一件事就是跟踪位置并进行API调用。
The only thing that I've newly added to my locationManager
class is the following extra check: 我新添加到locationManager
类的唯一一件事是以下额外检查:
private func checkLocationAccuracy(from location: CLLocation) throws {
let ageOfLocation = -location.timestamp.timeIntervalSinceNow
if ageOfLocation >= maximumAcceptedStale {
throw LocationAccuracyError.stale(secondsOld: ageOfLocation)
}
if location.horizontalAccuracy <= 0 {
throw LocationAccuracyError.invalid
}
if location.horizontalAccuracy > MaximumAcceptedHorizontalAccuracy{
throw LocationAccuracyError.lowAccuracy(metersOff: location.horizontalAccuracy)
}
}
If errors are thrown then I just log it. 如果抛出错误,那么我将其记录下来。 Otherwise I just make a network call. 否则,我只是打一个网络电话。 This extra check would reduce network calls, so I'm guessing it should more efficient energy wise. 这项额外的检查将减少网络呼叫,因此我猜测它应该更有效地节约能源。
There was a problem in the code written. 编写的代码有问题。
It was only happening when the user was making changes into the Location (permissions) Settings of the app. 仅在用户更改应用程序的“位置(权限)设置”时才发生。 Apparently that was a path that testing was not done against! 显然,这是没有针对测试的方法!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.