2

自从我更新到 iOS SDK 8 和 8.1 之后,出现了很多问题,包括不再调用 CLLocationManager 的 didUpdateLocations 方法。

这里的代码:在viewDidLoad中:

locationManager = [[CLLocationManager alloc] init];
locationManager.delegate = self;
locationManager.desiredAccuracy = kCLLocationAccuracyHundredMeters; // 100 m
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
    [locationManager requestAlwaysAuthorization];
}
[locationManager startUpdatingLocation];

方法:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"Call?"); }
4

4 回答 4

2

需要MapKit.framework包括Capabilities

在此处输入图像描述

于 2015-01-20T18:08:00.250 回答
2

几个想法:

  1. 你是在模拟器上还是在设备上测试这个?您必须在实际设备上对此进行测试。FWIW,didUpdateLocations在我的 iOS 8.1 设备上运行良好。

  2. 确保您指定了NSLocationAlwaysUsageDescription字符串,否则应用程序将不会显示授权消息,您将不会被授权。

    显然,如果你不需要“总是使用”,你应该只是requestWhenInUseAuthorization然后你必须指定NSLocationWhenInUseUsageDescription字符串。

  3. 你检查过[CLLocationManager authorizationStatus]吗?我什至在尝试授权或启动定位服务之前就这样做了,因为如果它是kCLAuthorizationStatusDeniedor kCLAuthorizationStatusRestricted,则定位服务将无法工作,直到用户进行设置并进行补救。如果您获得这些授权代码中的任何一个,您可能希望向他们显示一条消息。

  4. 你实施了locationManager:didFailWithError:吗?它有什么报告吗?

  5. 你实施了locationManager:didChangeAuthorizationStatus:吗?您是否以成功的授权状态调用此方法?

于 2014-10-25T03:46:32.120 回答
1

我有同样的问题,我的代码(viewdidupdate 方法)缺少这个:

_mapView.delegate = 自我;

出于某种原因,该应用程序在 ios 7 中运行,但在 ios 8.1 中从未调用过 didUpdateUserLocation。

于 2014-11-01T18:12:48.487 回答
1

在您的 plist 中同时指定NSLocationAlwaysUsageDescription 和 NSLocationWhenInUseUsageDescription :

在此处输入图像描述

同样在代码中,请求授权:

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { // or requestAlwaysAuthorization
    [self.locationManager requestWhenInUseAuthorization]; // or requestAlwaysAuthorization
}
[self.locationManager startUpdatingLocation];
于 2015-05-12T13:42:57.177 回答