后台运行的标准位置服务的 iOS 4 应用程序生命周期行为
我正在开发一个位置跟踪应用程序,它在后台使用标准位置服务和重大更改位置服务(我的应用程序在 iOS 4+ 中注册了后台位置更新)(如果适用)。感谢这个问题我对从后台状态返回并从终止状态重新启动的重大变化有多大。但是,我仍然不清楚标准位置服务在这些情况下的行为方式。任何人都可以分解后台运行的标准位置服务的确切行为吗?
具体来说:
- 当标准位置服务保持运行并且应用程序挂起到后台时,它会如何表现?从我自己的测试来看,我发现它将继续唤醒以接收
locationManager:didUpdateToLocation:fromLocation:
上的回调(我让它将位置发送到套接字,我可以在网络上看到它) )。此回调处理是否有时间或内存限制? - 即使我的应用程序终止,标准位置服务是否仍继续运行?也就是说,它是否会像重大变更服务那样使用
application:didFinishLaunchingWithOptions:
和UIApplicationLaunchOptionsLocationKey
重新启动?我认为在这种情况下 CLLocationManager 也需要重新启动,就像重大更改服务一样。
谢谢。
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:
- 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? - Does the standard location service continue to run even when my app is terminated? That is, will it ever relaunch with
application:didFinishLaunchingWithOptions:
withUIApplicationLaunchOptionsLocationKey
the way the significant change service does? I assume it theCLLocationManager
would also need to be restarted in this case, as the significant change service does.
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
回答 1 和 2 2,如果您已将应用程序注册为使用后台位置,则您的应用程序不会被终止并继续在后台运行,直到您执行此操作:
因此,没有时间或内存限制,但有电池限制。如果您的电池电量不足,所有使用 GPS 的应用程序都将被关闭。由于您的应用程序在正常情况下不会终止,因此不需要或不会使用
UIApplicationLaunchOptionsLocationKey
重新启动(在因电池原因而终止后)标准服务和重要服务的不同之处在于,显着唤醒当有位置更新时启动应用程序,但标准使应用程序连续运行,从而耗尽电池。
在选择要使用的服务之前,请考虑阅读 位置感知编程指南。
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:
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.