gpt4 book ai didi

iOS后台执行和防止应用程序被挂起/终止

转载 作者:行者123 更新时间:2023-11-28 17:53:07 27 4
gpt4 key购买 nike

我正在开发一个内部分发的 iOS 应用程序(即,没有应用程序商店),我希望能够以恒定的 10 分钟间隔报告设备的位置。

无论如何,我在我的 plist 中包含了 location 作为字段 UIBackgroundModes 中的键,希望这足以让我的应用程序在后台保持事件状态,同时我每次 10 分钟运行一次计时器。但是,我发现在某些情况下,应用程序会停止报告这些事件。我怀疑该应用程序正在进入暂停状态,甚至可能由于内存限制而终止。我已经使用仪器来分析我的内存占用,并且我已经排除了失控的内存分配是终止的原因。

如何防止系统将我的应用程序转入挂起状态?文档对位置背景模式这样说:

Enabling this mode does not prevent the system from suspending the app, but it does tell the system that it should wake up the app whenever there is new location data to deliver

太棒了。所以它可能会暂停,但新的位置数据会重新唤醒它。但是,如果没有新的位置数据怎么办?我可以防止应用程序被暂停吗?也许使用不同的背景模式?

非常感谢任何帮助!

最佳答案

你需要两件事来防止位置管理器暂停,有:

self.locationManager.allowsBackgroundLocationsUpdates= trueself.locationManager.pausesLocationUpdatesAutomatically = false

您可能还需要添加以下内容:self.locationManager.requestAlwaysAuthorization()

希望对您有所帮助,

关于iOS后台执行和防止应用程序被挂起/终止,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24947961/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com