打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
iOS应用后台运行GPS定位功能的实现

最近终于回归iOS了,一会来就碰到了定位相关的功能要求,客户要求即使应用挂起也可以执行GPS定位,并在位置发生变化时根据你的需要唤醒应用。

稍微研究了一下,实现方式跟音频后台播放类似,在应用的plist里添加后台运行设定即可。

Apple官方说明原文:

An app that provides continuous location updates to the user (even when in the background) can enable background location services by including the UIBackgroundModes key (with the location value) in its Info.plist file. The inclusion of this value in the UIBackgroundModes key does not preclude the system from suspending the app, but it does tell the system that it should wake up the app whenever there is new location data to deliver. Thus, this key effectively lets the app run in the background to process location updates whenever they occur.

实现方法是,在应用的info.plist里找到【Required background modes】项,在其中添加如下item: 【App registers for location updates】。

当上述设定完成后,只要你在应用中打开了GPS定位功能,即使程序挂起,仍然能够获取GPS定位信息。


有两点问题需要注意: 

1. 后台运行GPS定位非常消耗电量,所以建议在后台使用时降低GPS定位精度以节省用电,并确定你的用户确实需要这个功能,并在应用中给出提示说明。

2. 后台运行GPS定位有时间限制,大约10分钟时间,超过时间后系统会终止后台定位。

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
iOS中程序后台运行
可能是东半球最全的《iOS9 适配教程》
iOS 9 适配系列教程
6G内存依然卡顿,安卓手机超大运行内存只是噱头?
iOS为什么会这么流畅?明明苹果的运存比安卓小那么多,但流畅性
【【华为P8max】华为P8max【报价 参数 功能 性能 图片 怎么样】】
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服