gpt4 book ai didi

ios - iOS9 中 CLLocationManager 中的 allowsBackgroundLocationUpdates

转载 作者:IT王子 更新时间:2023-10-29 07:33:40 46 4
gpt4 key购买 nike

我在 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/

46 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com