iOS 多任务跟踪 GPS 位置
我只是想知道是否有可能制作一个 iOS 应用程序,在后台通过 GPS 跟踪您的位置。
我用内置应用程序“地图”尝试过此操作,但无济于事。
如果可能的话,如果您能给我推荐一些示例代码、文档或教程,那就太好了!
(如果这是重复的,请告诉我,我将删除它)
I was just wondering if it was possible to make an iOS app that would track your location via GPS while it was in the background.
I tried this with the built-in app "Maps", but to no avail.
If this is possible, it would be great if you could refer me to some sample code, documentations, or tutorials!
(if this is a duplicate, please let me know and I will remove it)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是可能的 - 请参阅本文档了解一般的多任务处理和 位置感知编程指南中“在后台获取位置事件”的这一部分。当然,所有这些都讨论了 iOS 设备获取您位置的各种方式(手机信号塔三角测量、Skyhook 式 wifi 网络观测和 GPS),而不是专有的 GPS。
简而言之,通过阅读这些文档:将 UIBackgroundModes 键添加到您的 info.plist(这是一个数组)中,并将值“location”放入其中。即使在后台,您也会收到 CLLocationManager 更新。
但是,如果您想节省电池电量,那么最好使用 CLLocationManager 上的 startMonitoringSignificantLocationChanges 方法。然后,即使在后台,您也可以获得适当的重要位置更新,而不是一个完整的后台应用程序。该文档的其他部分指出,重大更改是从一个蜂窝塔到另一个蜂窝塔的任何更改。
This is possible — see this document for multitasking in general and this section of the Location Awareness Programming Guide for "Getting Location Events in the Background". Of course, all these talk about all of the various ways an iOS device can get your location (cell tower triangulation, Skyhook-style wifi network observation and GPS), not exclusive GPS.
In short, from reading those docs: add the UIBackgroundModes key into your info.plist, which is an array, and put the value 'location' into it. You'll then receive CLLocationManager updates even when in the background.
However, if you want to be nice to the battery then you're better off using the startMonitoringSignificantLocationChanges method on a CLLocationManager. Then you get suitably significant location updates even when in the background without being a full on background app. Other parts of the documentation state that a significant change is any change from one cell tower to another.