未调用位置管理器的委托方法

问题描述 投票:1回答:1

未调用位置管理器didUpdateLocations。

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

self.locationManager.delegate = self;

[self.locationManager startUpdatingLocation];

用于回叫,我正在使用此委托方法

- (void)locationManager:(CLLocationManager )manager didUpdateLocations:(NSArray )locations
{
    NSLog(@"%@", [locations lastObject]);
}
ios location
1个回答
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来请求权限以明确使用位置服务。

© www.soinside.com 2019 - 2024. All rights reserved.