use*_*060 2 core-location cllocationmanager ios
在设置应用程序>隐私>位置服务>我的应用程序>从不在后台模式下,didChangeAuthorizationStatus被称为kCLAuthorizationStatusDenied状态.但在更改"Always"之后,未调用didChangeAuthorizationStatus.关闭"位置服务"时也不会调用.
我在Info.plist中插入了NSLocationAlwaysUsageDescription并设置了位置更新后台模式.
我的代码,
- (id)init {
self = [super init];
if (self) {
_locationManager = [[CLLocationManager alloc] init];
_locationManager.delegate = self;
_locationManager.pausesLocationUpdatesAutomatically = NO;
if ([_locationManager respondsToSelector:@selector(setAllowsBackgroundLocationUpdates:)]) {
NSLog(@"setAllowsBackgroundLocationUpdates");
_locationManager.allowsBackgroundLocationUpdates = YES;
}
[self requestAuthorization];
}
return self;
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
NSLog(@"CLAuthorizationStatus: %d", status);
}
Run Code Online (Sandbox Code Playgroud)
对不起我的英文.
我遇到了这个确切的问题,事实证明我正在制作我的CLLocationManager电话
-requestWhenInUseAuthorization
在背景线程上.我在主线程上调用了这些方法并获得了预期的结果(-locationManager:didChangedAithorizationStatus:在我点击"不允许"或"允许"后调用)