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

来源:互联网 发布:信捷xc软件 编辑:程序博客网 时间:2024/06/06 01:50

报错的原因是没有开启定位的后台访问权限


解决方法:

1. 前台访问:

.plist配置NSLocationWhenInUseUsageDescription

1. 后台访问:

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

设置CLLocationManager的allowsBackgroundLocationUpdatesYES

然后打开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


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

先看下官方文档怎么说:

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的值进行判断以确定当前位置是否有效

阅读全文
0 0
原创粉丝点击