位置管理器的delagate方法没有被调用

时间:2015-09-17 10:44:29

标签: ios location

位置管理器didUpdateLocations未被调用。

self.locationManager = [[CLLocationManager alloc] init];

self.locationManager.delegate = self;

[self.locationManager startUpdatingLocation];

for call back i am using this delegate method 

- (void)locationManager:(CLLocationManager )manager didUpdateLocations:(NSArray )locations
{
    NSLog(@"%@", [locations lastObject]);
}

1 个答案:

答案 0 :(得分:0)

导入框架CoreLocation

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

在iOS8及更高版本中,您必须通过调用requestAlwaysAuthorization或requestWhenInUseAuthorization来请求显式使用位置服务的权限。