iOS9中的CLLocationManager中的allowsBackgroundLocationUpdates [英] allowsBackgroundLocationUpdates in CLLocationManager in iOS9

查看:1463
本文介绍了iOS9中的CLLocationManager中的allowsBackgroundLocationUpdates的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm using CoreLocation framework in my app in Xcode7(pre-released),and I noticed that there is a newly added property called allowsBackgroundLocationUpdates in CLLocationManager class.

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

What's the relationship between this property and the location updates in the Background Modes of the Capabilities tab. What's the default value of it and does it affect apps running in iOS9?

推荐答案

这个新属性在WWDC会话中进行了解释< a href =https://developer.apple.com/videos/wwdc/2015/?id=714 =noreferrer>核心位置有什么新功能。

This new property is explained in the WWDC session "What's New in Core Location".

如果您链接iOS 9,则默认值为

The default value is NO if you link against iOS 9.

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

If your app uses location in the background (without showing the blue status bar) you have to set allowsBackgroundLocationUpdates to YES in addition to setting the background mode capability in Info.plist. Otherwise location updates are only delivered in foreground. The advantage is that you can now have location managers with background location updates and other location managers with only foreground location updates in the same app. You can also reset the value to NO to change the behavior.

文档非常清楚:


默认情况下,对于iOS 9.0或
之后链接的应用程序,这是NO,无论最低部署目标如何。

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

当UIBackgroundModes设置为在Info.plist中包含location时,
也必须在运行时将此属性设置为YES,只要调用
-startUpdatingLocation,意图是继续在后台。

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.

当UIBackgroundModes不包含
location时将此属性设置为YES是致命错误。

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

将此属性重置为NO相当于从UIBackgroundModes值中省略location
。在应用程序运行时(即未暂停),允许访问位置仍为
,并且
具有足够的授权(即,它具有WhenInUse授权并且在使用中为
,或者它具有始终授权) 。但是,该应用程序仍将按照通常的任务暂停规则进行

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.

请参阅-requestWhenInUseAuthorization和-requestAlwaysAuthorization for
有关可能授权的详细信息值。

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

这篇关于iOS9中的CLLocationManager中的allowsBackgroundLocationUpdates的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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