使用CLLocationManager获取当前位置。特别是在iOS 8中,它的委托方法不会被解雇。
我在位置服务中设置了允许请参考下面的屏幕截图
请在下面找到我的代码:
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];
答案 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
答案 1 :(得分:0)
您似乎没有为NSLocationAlwaysUsageDescription
设置值。