ios - 后台位置更新会导致应用程序强制终止吗?

标签 ios location core-location cllocationmanager background-process

我有一个使用定位服务的应用程序。当应用程序处于前台和后台时,它将向服务器发送位置数据。

由于大量使用定位服务,系统可能会强制终止我的应用程序吗?还是我的测试人员注意到位置数据中的“差距”是由于 GPS/互联网信号不佳?

最佳答案

根据App Programming Guide for iOS :

在 App Termination 部分(重点添加),

Apps must be prepared for termination to happen at any time and should not wait to save user data or perform other critical tasks. System-initiated termination is a normal part of an app’s life cycle. The system usually terminates apps so that it can reclaim memory and make room for other apps being launched by the user, but the system may also terminate apps that are misbehaving or not responding to events in a timely manner.

Apple 并未定义“行为不当”,但在后台状态下频繁发出网络或 GPS 位置请求根本就不是一个好公民。您可以通过订阅精度较低的位置更改来降低这些更新的频率。 (Apple 强烈推荐显着变化位置服务。)

除非精确和连续的位置数据对您的应用至关重要(例如导航应用可能就是这种情况),否则您应该尽量限制在后台状态下使用位置服务。

来自Background Execution section同一个指南,

Apps that need to run in the background to support specific types of tasks can declare their support for one or more background execution modes.

因此,如果您碰巧需要尽可能准确的位置更新,并且您正确地声明了对该后台模式的支持,那么系统可能会更容忍任何频繁的后台任务执行、资源占用或其他“不当行为”。但是,声明支持后台模式并不能免除您的应用程序尝试最小化其资源使用足迹的责任;你还是应该努力做一个好公民。


回答你的问题,

  • 是的。如果您的应用变得无响应或行为不当,系统可能会强制终止该应用。
  • 您注意到的“差距”可能是由于 GPS 或互联网连接不佳造成的。然而,还有许多其他因素会影响系统如何为应用程序分配资源以及系统允许后台应用程序“唤醒”的频率。因此,我们只能推测您遇到这种差距的原因。

关于ios - 后台位置更新会导致应用程序强制终止吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31400003/

相关文章:

ios - Xcode 模拟位置 GPX 在构建时崩溃

ios - 使用 UItableViewCell 类型的表达式初始化 'CustomCellView *' 的不兼容指针类型

ios - 如何正确地在具有内在内容大小的 View 之间进行约束?

ios - 将 CIFilter 应用于 UIImagePickerController 提要

java - Android:如何使用 GPS 提供商获取离线当前位置?

android - 如果设备没有移动,则停止位置更新,如果移动了 300m 的距离,则获取其位置

java - 如何获得 Canvas 的确切位置(Java)

swift - 如何在 OS X Today 扩展中使用 CLLocationManager?

ios - 如何从 swift 中的 didUpdateToLocation 方法获取旧位置值

ios - 是否可以添加一个 UIView 作为 UINavigationBar 的背景