ios - iOS9 中 CLLocationManager 中的 allowsBackgroundLocationUpdates

标签 ios ios9 core-location cllocationmanager

我在 Xcode7(预发布)的应用程序中使用 CoreLocation 框架,我注意到 中有一个名为 allowsBackgroundLocationUpdates 的新添加属性CLLocationManager 类。

此属性与功能选项卡的背景模式中位置更新之间的关系是什么。它的默认值是多少,它会影响在 iOS9 中运行的应用程序吗?

最佳答案

这个新属性在 WWDC session 中有解释 "What's New in Core Location" .

如果您针对 iOS 9 进行链接,则默认值为 NO

如果您的应用程序在后台使用位置信息(不显示蓝色状态栏),除了在 Info 中设置后台模式功能外,您还必须将 allowsBackgroundLocationUpdates 设置为 YES .plist。否则位置更新仅在前台传送。优点是您现在可以在同一个应用程序中拥有具有后台位置更新的位置管理器和仅具有前台位置更新的其他位置管理器。您还可以将值重置为 NO 以更改行为。

文档对此非常清楚:

By default, this is NO for applications linked against iOS 9.0 or later, regardless of minimum deployment target.

With UIBackgroundModes set to include "location" in Info.plist, you must also set this property to YES at runtime whenever calling -startUpdatingLocation with the intent to continue in the background.

Setting this property to YES when UIBackgroundModes does not include "location" is a fatal error.

Resetting this property to NO is equivalent to omitting "location" from the UIBackgroundModes value. Access to location is still permitted whenever the application is running (ie not suspended), and has sufficient authorization (ie it has WhenInUse authorization and is in use, or it has Always authorization). However, the app will still be subject to the usual task suspension rules.

See -requestWhenInUseAuthorization and -requestAlwaysAuthorization for more details on possible authorization values.

关于ios - iOS9 中 CLLocationManager 中的 allowsBackgroundLocationUpdates,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30808192/

相关文章:

iphone - 在 iPhone 模拟器上模拟位置更新

ios - 如何阅读电话簿号码标签?

ios - 在 Xcode 6 中测试覆盖率文件

objective-c - SFSafariViewController 状态栏样式

ios - 识别是否在模拟器ios9中运行

swift - macos CLLocationManager 提示

java - 从 iOS 到 Android : Some beginner's questions

iphone - UIView 子类中使用的 CAShapeLayer 不起作用

ios - 在 iOS 9 中隐藏复制/粘贴/返回面板(快捷方式面板)

ios - 如何判断iOS硬件是否有GPS