xcode iOS 多任务跟踪 GPS 位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4400628/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 19:59:06  来源:igfitidea点击:

iOS Multi-Tasking Track GPS Location

iphonexcodegpsmultitasking

提问by Linuxmint

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.

我只是想知道是否有可能制作一个 iOS 应用程序,当它在后台时通过 GPS 跟踪您的位置。

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)

(如果这是重复的,请告诉我,我会删除它)

回答by Tommy

This is possible — see this documentfor 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.

这是可能的 - 请参阅此文档以了解一般的多任务处理以及“在后台获取位置事件”的位置感知编程指南的这一部分。当然,所有这些都在谈论 iOS 设备获取您位置的各种方式(手机信号塔三角测量、Skyhook 式 wifi 网络观察和 GPS),而不是专属 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.

简而言之,通过阅读这些文档:将 UIBackgroundModes 键添加到您的 info.plist 中,这是一个数组,并将值 'location' 放入其中。即使在后台,您也会收到 CLLocationManager 更新。

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.

但是,如果您想对电池好一点,那么最好在 CLLocationManager 上使用 startMonitoringSignificantLocationChanges 方法。然后,即使在后台而不是完整的后台应用程序,您也可以获得适当的重要位置更新。文档的其他部分指出,从一个蜂窝塔到另一个蜂窝塔的任何变化都是重大变化。