
[英]iOS 8 CLLocationManager enterRegion: not getting called if use requestWhenInUseAuthorization
[英]iOS8 when to alloc init CLLocationManager to call requestWhenInUseAuthorization?
当我尝试在其getter内分配初始化我的CLLocationManager时,我没有收到针对位置自动化的弹出请求。 但是,当我放入viewDidLoad时,它确实可以工作。
我的代码看起来像这样:
- (void)viewDidLoad {
[super viewDidLoad];
self.mapView.delegate = self;
self.locationManager = [[CLLocationManager alloc] init]; //when i put this here it works
self.locationManager.delegate = self;
CLAuthorizationStatus status = [CLLocationManager authorizationStatus];
if(![CLLocationManager authorizationStatus])
{
[self.locationManager requestWhenInUseAuthorization];
}
self.mapView.showsUserLocation = YES;
[self.mapView setMapType:MKMapTypeStandard];
[self.mapView setZoomEnabled:YES];
[self.mapView setScrollEnabled:YES];
}
但是当我像这样进行分配初始化时,它不起作用:
-(CLLocationManager *)locationManager
{
if(_locationManager) _locationManager = [[CLLocationManager alloc]init];
return _locationManager;
}
谁能向我解释为什么?
由于访问器方法中存在逻辑错误,因此:
- (CLLocationManager *)locationManager
{
if(_locationManager == nil) _locationManager = [[CLLocationManager alloc] init];
return _locationManager;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.