iPhone定期后台任务

发布于 2024-09-30 14:10:37 字数 243 浏览 5 评论 0原文

我有一个问题,我想定期收集 GPS 数据,比如每 5 分钟一次。当应用程序运行时,我可以毫无问题地执行此操作。不过我想知道是否有一种标准方法可以使用 iPhone 的“多任务处理”来做到这一点。我可以使用后台进程使用不断更新的模型和重大变化来收集数据,但这些数据要么太耗电,要么不准确。

我正在查看 NSLocalNotification,但是我不确定在定期检查位置时是否将应用程序保持在后台状态,我认为这只能选择启动应用程序。

提前致谢。

I have and issue where i want to collect GPS data periodically, say every 5 minutes. I can do this no problem when the app is running. However i wanted to know if there is a standard way to do this using the iPhone 'multitasking'. I can collect the data using the background process using the constant updating model and the significant changes, but these are either too battery intensive or to inaccurate.

I am in the process at looking the the NSLocalNotification, how ever i'm not sure the keeps the app in a background state while checking location periodically, i think this only has the option of launching the app.

Thank in advance.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

停顿的约定 2024-10-07 14:10:37

无法定期执行 GPS 采集(例如每 5 分钟一次)。

来自苹果文档:

节省电池电量的技巧

使用基于 iOS 的设备的无线电接收和传输数据比设备上的任何其他操作需要更多的电量。由于 Core Location 依赖这些无线电来确定用户的位置,因此您应该在应用程序中明智地使用位置服务。大多数应用程序不需要始终运行位置服务,因此关闭这些服务是最简单的省电方法。

  • 在不使用定位服务时将其关闭。这可能看起来很明显,但值得重复。除了提供路线导航的导航应用程序外,大多数应用程序不需要始终开启定位服务。打开定位服务足够长的时间以获得位置修复,然后将其关闭。除非用户位于移动的车辆中,否则当前位置的变化不应频繁到成为问题。如果需要,您可以随时重新启动位置服务。
  • 尽可能使用重大更改位置服务而不是标准位置服务。重大更改位置服务可显着节省电量,同时仍允许您保持位置服务运行。对于需要跟踪用户位置变化但不需要标准位置服务提供的更高精确度的应用程序,强烈建议这样做。
  • 使用较低的分辨率值来获得所需的精度,除非这样做会损害您的应用程序。请求比您需要的精度更高的精度会导致 Core Location 启动额外的硬件并浪费电力来实现您不想要的精度使用。除非您的应用程序确实需要知道用户在几米范围内的位置,否则请勿将 kCLLocationAccuracyBest 或 kCLLocationAccuracyNearestTenMeters 值放入desiredAccuracy 属性中。请记住,指定 kCLLocationAccuracyThreeKilometers 值不会阻止位置服务返回更好的数据。大多数时候,Core Location 可以使用 Wi-FI 和蜂窝信号返回精确度在百米左右的位置数据。
  • 如果准确性在一段时间内没有提高,请关闭位置事件。如果您的应用程序未接收到具有所需准确度级别的事件,您应该检查您接收的事件的准确性接收并查看随着时间的推移它是否有所改善或保持不变。如果准确性没有提高,可能是因为目前无法达到所需的准确性。关闭位置服务并稍后重试可防止您的应用程序浪费电量。

There is no way to perform periodically GPS acquisition (each 5 min for example).

From Apple documentation:

Tips for Conserving Battery Power

Receiving and transmitting data using the radios of an iOS-based device require more power than any other operation on the device. Because Core Location relies on these radios to determine the user’s location, you should use location services judiciously in your applications. Most applications do not need location services to be running all the time, and so turning off those services is the simplest way to save power.

  • Turn off location services when you are not using them. This may seem obvious but it is worth repeating. With the exception of navigation applications that offer turn-by-turn directions, most applications do not need location services to be on all the time. Turn location services on just long enough to get a location fix and then turn them off. Unless the user is in a moving vehicle, the current location should not change frequently enough to be an issue. And you can always start location services again later if needed.
  • Use the significant-change location service instead of the standard location service whenever possible. The significant-change location service provides significant power savings while still allowing you to leave location services running. This is highly recommended for applications that need to track changes in the user’s location but do not need the higher precision offered by the standard location services.
  • Use lower-resolution values for the desired accuracy unless doing so would impair your application. Requesting a higher accuracy than you need causes Core Location to power up additional hardware and waste power for precision you are not using. Unless your application really needs to know the user’s position within a few meters, do not put the values kCLLocationAccuracyBest or kCLLocationAccuracyNearestTenMeters in the desiredAccuracy property. And remember that specifying a value of kCLLocationAccuracyThreeKilometers does not prevent the location service from returning better data. Most of the time, Core Location can return location data with an accuracy within a hundred meters or so using Wi-FI and cellular signals.
  • Turn off location events if the accuracy does not improve over a period of time. If your application is not receiving events with the desired level of accuracy, you should look at the accuracy of events you do receive and see if it is improving or staying about the same over time. If accuracy is not improving, it could be because the desired accuracy is simply not available at the moment. Turning off location services and trying again later prevents your application from wasting power.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文