您的位置:首页 > 其它

Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)解决方法

2017-08-11 14:21 495 查看
报错的原因是没有开启定位的后台访问权限

解决方法:

1. 前台访问:

为.plist配置NSLocationWhenInUseUsageDescription


1. 后台访问:

一种方法是处在拥有
前台定位权限
的情况下:

设置CLLocationManager的
allowsBackgroundLocationUpdates
YES


然后打开Xcode -> Targets -> Capabilities 中的Background Modes并勾选其中的
Location updates
选项

以上步骤也可以通过以下配置.plist文件的方式实现 :

<!--开启Background Modes中的Location updates-->
<key>UIBackgroundModes</key>
<array>
<string>location</string>
</array>


切记
如果不开启Background Modes的Location updates选项将会导致以下错误的出现:

Assertion failure in -[CLLocationManager setAllowsBackgroundLocationUpdates:], /BuildRoot/Library/Caches/com.apple.xbs/Sources/CoreLocationFramework_Sim/CoreLocation-1861.0.9/Framework/CoreLocation/CLLocationManager.m:604
*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid parameter not satisfying: !stayUp || CLClientIsBackgroundable(internal->fClient)'


当然这种获取后台位置访问权限的方式有一个”弊端”, 那就是会有一个导航条大小的蓝色提示窗口出现在手机屏幕顶端, 这个提示会挤占手机屏幕空间, 很神奇~

我猜你一定喜欢另一种进行后台位置访问的方法, 那就是直接请求后台定位权限:

- (void)requestAlwaysAuthorization
// 并为.plist配置NSLocationAlwaysUsageDescription


CLLocation

关于这个类想说的东西只有一个, 那就是它的
horizontalAccuracy
verticalAccuracy
属性, 从字面上看好像是水平精度和垂直精度的意思

先看下官方文档怎么说:

The radius of uncertainty for the location, measured in meters. (read-only)

The location’s latitude and longitude identify the center of the circle, and this value indicates the radius of that circle. A negative value indicates that the location’s latitude and longitude are invalid.

In iOS, this property is declared as nonatomic. In OS X, it is declared as atomic.

我的理解是, 从地理空间的角度看, Apple称通过经纬度确定的位置为水平位置, 而通过海拔确定的位置是垂直位置, horizontalAccuracy则是通过该位置的经度和纬度确定的圆的半径. 该值越大表示精度越低, 也就是位置越不准确, 而负值则表示该位置是无效的, verticalAccuracy和海拔的关系也是如此, 官方文档说的应该很清楚了

在实际开发过程常常会对horizontalAccuracy的值进行判断以确定当前位置是否有效
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  xcode
相关文章推荐