iOS 8 CLLocationManager enterRegion:如果使用 requestWhenInUseAuthorization 则不会被调用

iOS 8 CLLocationManager enterRegion: not getting called if use requestWhenInUseAuthorization

我正在尝试在 iOS 8 中为自定义区域调用委托方法 locationManager:didEnterRegion。这是代码:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}

CLCircularRegion *region = [[CLCircularRegion alloc] initWithCenter:CLLocationCoordinate2DMake(20, 20) radius:1000 identifier:@"asda"];
region.notifyOnEntry = YES;
region.notifyOnExit = YES;
[self.locationManager startMonitoringForRegion:region];

它会调用方法 locationManager:didStartMonitoringForRegion,但不会调用 "enter" 或 "exit" 区域方法。

更奇怪的是,如果我对 locationManager 使用 requestAlwaysAuthorization,它确实有效。但我需要让它与 "When In Use".

一起工作

注意:在 iOS7 中,它适用于 WhenInUse 和 Always Authorization 方法。

区域监控 - 它不适用于 requestWhenInUseAuthorization

查看 Apple 文档: “.. “when-in-use” ... Apps cannot use any services that automatically relaunch the app, such as region monitoring or the significant location change service

你必须打电话requestAlwaysAuthorization!!! https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization