iOS 多任务跟踪 GPS 位置 [英] iOS Multi-Tasking Track GPS Location

查看:22
本文介绍了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)

推荐答案

这是可能的 — 请参阅 本文档 用于一般的多任务处理和 在后台获取位置事件"的位置感知编程指南的这一部分.当然,所有这些都在讨论 iOS 设备获取您位置的所有各种方式(蜂窝塔三角测量、Skyhook 式 wifi 网络观测和 GPS),而不是唯一的 GPS.

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.

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

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.

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

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.

这篇关于iOS 多任务跟踪 GPS 位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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