标准位置服务在后台运行的iOS 4应用程序生命周期行为 [英] iOS 4 application lifecycle behavior of standard location service running in background

查看:128
本文介绍了标准位置服务在后台运行的iOS 4应用程序生命周期行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在研究位置跟踪应用程序,该应用程序在后台同时使用标准位置服务和重要更改位置服务(我的应用程序已注册iOS 4中的后台位置更新)。感谢这个问题我对于来自背景状态的重大变化有多大,并从终止状态重新开始。但是,我仍然不清楚标准位置服务在这些情况下的行为。任何人都可以分解标准位置服务在后台运行的确切行为吗?

具体来说:


  1. 标准位置服务在您离开它时运行并且应用程序挂起到后台?从我自己的测试中,我已经看到它会继续唤醒接收 locationManager上的回调函数:didUpdateToLocation:fromLocation:(我将它从套接字发送出去,而我可以在网络上看到它)。是否有此回调处理的时间或内存限制?

  2. 标准位置服务即使在我的应用程序终止时也能继续运行吗?也就是说,它是否会重新启动 application:didFinishLaunchingWithOptions: UIApplicationLaunchOptionsLocationKey 重要更改服务的方式?我认为在这种情况下, CLLocationManager 也需要重新启动,因为重大更改服务的确如此。

谢谢。

解决方案

回答1& 2,如果你已经注册你的应用程序作为使用背景位置,那么你的应用程序不会终止,并继续在后台运行,直到你这样做:

  [locationManager stopUpdatingLocation]; 

因此,没有时间或内存限制,但是存在电池限制。如果电池电量不足,所有使用gps的应用程序将被关闭。由于您的应用在正常情况下没有终止,无论是不是必须的,或者它不会以 UIApplicationLaunchOptionsLocationKey

$ b重新启动(在终止使用电池后)
$ b

标准服务和重要服务在这种方式下有所不同,当有位置更新时,会显着唤醒应用程序,但标准会使应用程序不断运行并因此耗尽电池。

在您选择要使用的服务之前,请考虑阅读位置感知编程指南。


I'm working on a location tracking application that uses both the standard location service and significant change location service in the background (my app is registered for background location updates in iOS 4+) as applicable. Thanks to this question I have a solid understanding of how significant change comes back from the background state and relaunches from a terminated state. However, I'm still not clear on how the standard location service behaves in these instances. Could anyone break down the exact behavior of the standard location service running in the background?
Specifically:

  1. How does the standard location service behave when you leave it running and the app suspends into the background? From my own testing, I've seen that it will continue waking up to receive callbacks on locationManager:didUpdateToLocation:fromLocation: (I have it send the location out a socket and I can see it on the network). Is there a time or memory limit for this callback to process?
  2. Does the standard location service continue to run even when my app is terminated? That is, will it ever relaunch with application:didFinishLaunchingWithOptions: with UIApplicationLaunchOptionsLocationKey the way the significant change service does? I assume it the CLLocationManager would also need to be restarted in this case, as the significant change service does.

Thanks.

解决方案

Answer to both 1 & 2, If you have registered your app as using background location then your app does not get terminated and continues to run in the background until you do this:

[locationManager stopUpdatingLocation];

So, there is no time or memory limit however there is a battery limit. If your battery is low, all apps using gps will be closed. Since your app is not terminated in normal circumstances, either it is not required to or it does not relaunch (after being terminated coz of battery) with UIApplicationLaunchOptionsLocationKey

Standard and significant services are different in this manner that significant wakes up the app whenevr there is a location update but standard makes app run continuously and hence drain battery.

Before you choose what service to use consider reading the Location-Awareness Programming guide.

这篇关于标准位置服务在后台运行的iOS 4应用程序生命周期行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆