简体   繁体   English

如果我开启了位置服务,那么进入后台模式后如何杀死我的应用?

[英]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.

相关问题 即使应用在iOS中被杀死或从后台删除,我如何继续更新我的位置? - How Can I Continue updating my location even when app is killed or removed from background in ios? 当应用程序处于后台或被杀时,如何定期获取新位置 - How to get periodicaly new location when app is in background or killed 进入后台模式时,如何在应用中更新位置管理器和计时器? - How can i update location manager and a timer in my app when it goes to background mode? 我已导入 AVFoundation 并将音频添加到我的应用程序,但如果应用程序进入后台模式,音频不会停止 - I have Imported AVFoundation and added Audio to my app but if the App enters the background mode the audio isn't stop 当应用程序进入后台时,如何使我的应用程序弹出到VC? - How can I make my app pop to a VC when the app enters the background? 当我的应用进入后台时,如何停止Google Analytics(分析)跟踪会话? - How can I stop Google analytics tracking session when my app enters into background? 当我的应用程序中的位置服务关闭时,如何显示包含设置+取消按钮的UIAlertView? - How to present UIAlertView which contains Settings + Cancel button when location services are turned off in my app? 应用程序被杀死后,如何找到用户的位置? - how can i find users location when app is killed ? 即使我要求在后台更新位置,为什么我的iOS应用程序会被杀死? - Why does my iOS app get killed even though I ask for location updates in the background? 当我的应用程序进入后台时,是否可以将循环放入dispatch_async中? - Can I put a loop into dispatch_async when my app enters in background?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM