CLLocationmanager updateLocations委托方法未在iOS 8中调用

时间:2014-09-23 11:25:12

标签: ios objective-c mapkit

使用CLLocationManager获取当前位置。特别是在iOS 8中,它的委托方法不会被解雇。

我在位置服务中设置了允许请参考下面的屏幕截图 enter image description here

请在下面找到我的代码:

self.myLocationManager = [[CLLocationManager alloc]init]; [self.myLocationManager setDelegate:self]; self.myLocationManager.distanceFilter = kCLDistanceFilterNone; self.myLocationManager.desiredAccuracy = kCLLocationAccuracyBest; [self.myLocationManager startUpdatingLocation];

我尝试使用iOS 8的方法。并在plist中设置属性NSLocationAlwaysUsageDescription,但仍然无法获取位置

self.myLocationManager requestAlwaysAuthorization];

2 个答案:

答案 0 :(得分:1)

第1步:

添加以下代码:

SEL requestSelector = NSSelectorFromString(@"requestAlwaysAuthorization");
if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined &&
    [locationManager respondsToSelector:requestSelector]) {
    [locationManager performSelector:requestSelector withObject:NULL];
} else {
    [locationManager startUpdatingLocation];
}

第2步:

NSLocationAlwaysUsageDescription添加到info.plist

enter image description here

答案 1 :(得分:0)

您似乎没有为NSLocationAlwaysUsageDescription设置值。