didUpdateLocations未调用

didUpdateLocations未调用

本文介绍了didUpdateLocations未调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试获取当前位置,但是didUpdateLocations中的断点永远不会被调用。

I'm trying to get my current location, but the break point in didUpdateLocations is never being called.

LocationManager:

LocationManager:

locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyBest];
[locationManager setDesiredAccuracy:kCLDistanceFilterNone];
[locationManager startUpdatingLocation];

委托方式:

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations;

我确认了位置服务和启用和授权。

I confirmed that location services and enabled and authorized.

为什么没有像它应该调用locationManager委托方法?

Why is the locationManager delegate method not being called like it should?

谢谢,
Mike

Thanks,Mike

推荐答案

此外,在iOS8中,你必须有两件额外的东西:

Furthermore in iOS8 you must have two extra things:


  • Info.plist 中添加一个密钥,并请求位置管理员授权启动。

  • Add a key to your Info.plist and request authorization from the location manager asking it to start.


  • NSLocationWhenInUseUsageDescription

NSLocationAlwaysUsageDescription

您需要请求相应位置方法的授权。

You need to request authorization for the corresponding location method.


  • [self.locationManager requestWhenInUseAuthorization]

[self.locationManager requestAlwaysAuthorization]

代码示例:

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
// Check for iOS 8. Without this guard the code will crash with "unknown selector" on iOS 7.
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
    [self.locationManager requestWhenInUseAuthorization];
}
[self.locationManager startUpdatingLocation];

资料来源:

这篇关于didUpdateLocations未调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 11:00