iOS 8 CLLocationManager enterRegion: not getting called if use requestWhenInUseAuthorization

怎甘沉沦 提交于 2019-12-02 04:23:41

问题


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:


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



来源:https://stackoverflow.com/questions/30727102/ios-8-cllocationmanager-enterregion-not-getting-called-if-use-requestwheninusea

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!