iOS 8 CLLocationManager enterRegion: not getting c

2020-04-16 04:46发布

I'm trying to get being called the delegate method locationManager:didEnterRegion in iOS 8 for custom region. Here is the code:

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];

It does call method locationManager:didStartMonitoringForRegion, but it doesn't call "enter" or "exit" region methods.

The one more strange thing is that it DOES work if I use requestAlwaysAuthorization for locationManager. But I need to get it worked with "When In Use".

Note: In iOS7 it works for both WhenInUse and Always Authorization methods.

1条回答
Juvenile、少年°
2楼-- · 2020-04-16 05:37

region monitoring - it's not working with requestWhenInUseAuthorization

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

You must call requestAlwaysAuthorization!!! https://developer.apple.com/library/ios/documentation/CoreLocation/Reference/CLLocationManager_Class/index.html#//apple_ref/occ/instm/CLLocationManager/requestWhenInUseAuthorization

查看更多
登录 后发表回答