ios - 在 iOS 中实现长时间运行的后台任务

标签 ios app-store background-process

我的客户让我开发一些应用程序,定期检索用户位置和手机电池状态,然后将它们发送到我们的后端服务器进行数据分析,然后通过推送通知反馈。

但是通过应用文档,我从 apple ios dev 了解到 doc :

For tasks that require more execution time to implement, you must request specific permissions to run them in the background without their being suspended. In iOS, only specific app types are allowed to run in the background:

Apps that play audible content to the user while in the background, such as a music player app

Apps that keep users informed of their location at all times, such as a navigation app

Apps that support Voice over Internet Protocol (VoIP)

Newsstand apps that need to download and process new content

Apps that receive regular updates from external accessories

我想知道如果我们将这个应用程序包装成一些导航应用程序这样我们可以有长时间运行的后台任务,这是否可行?应用商店会拒绝我们的应用吗?

顺便说一句,Apple 对导航应用程序的定义是什么?

最佳答案

您可以考虑使用:

[CLLocationManager startMonitoringSignificantLocationChanges];

如果您的应用程序在位置显着变化时被终止,这将导致您的应用程序重新启动,从而允许您以相当定期的时间间隔更新服务器上的详细信息,假设用户正在移动。这不需要任何特殊的后台许可。来自文档:

If you start this service and your application is subsequently terminated, the system automatically relaunches the application into the background if a new event arrives. In such a case, the options dictionary passed to the locationManager:didUpdateLocations: method of your application delegate contains the key UIApplicationLaunchOptionsLocationKey to indicate that your application was launched because of a location event.

您的另一个选择是将应用配置为需要在后台持续更新位置,但在不知道应用的主要功能的情况下,很难知道这是否会通过商店提交。

关于ios - 在 iOS 中实现长时间运行的后台任务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16747267/

相关文章:

ruby-on-rails - Rails 中的后台处理

ios - 100% 屏幕宽度在 iPhone 上的 Salesforce1 中无法正常工作

ios - 上传二进制文件后更改元数据

ios - UIDatePicker选择的日期不出现

ios - 如何启用从 iOS 应用程序向 iTunesConnect 提交崩溃报告?

iphone - 通过 App Store 分发第三方开发的应用程序

macos - 后台进程在 OS X 上显示为 "not responding"

android - 如何在 Android 8.0 中正确更新小部件 - Oreo - API 26

iOS EKEventEditViewController 如何强制警报到 "At time of event"?

ios - 在 iOS 中,如何从正在运行的应用程序内部获取当前 CPU 利用率?