我想得到当前的位置,但是我得到了一个错误。
这是我的视图控制器的一个片段。
- (void)viewDidLoad {
self.locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
[locationManager setDesiredAccuracy:kCLLocationAccuracyNearestTenMeters];
[locationManager startUpdatingLocation];
}
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations {
// I would get the latest location here
// but this method never gets called
}
- (void)locationManager:(CLLocationManager *)manager
didFailWithError:(NSError *)error {
NSLog(@"didFailWithError: %@", error);
}
我期望调用委托方法locationManager:didUpdateLocations:
,但实际上只有locationManager:didFailWithError:
被调用,并打印以下内容:
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
发布于 2014-09-10 11:25:26
只需忽略此错误并等待更多更新或其他错误。
位置管理器的文档说这个错误是暂时的。它会让您知道它未能立即检索到某个位置,但它会继续尝试。在这种情况下,您可以忽略错误并等待新事件。这是使用名为locationManager:didFailWithError:
的方法的一种非常愚蠢的方式--谢谢苹果!
发布于 2013-12-19 00:24:13
尝试重新启动模拟器(假设您正在使用该模拟器)。
在尝试了其他方法之后,这对我来说是有效的。
发布于 2015-03-24 01:46:15
我在模拟器上得到了这个错误。单击“调试”面板中的“位置”按钮并设置一个位置,为我修复了这个问题。(确保按钮为蓝色)
https://stackoverflow.com/questions/6032976
复制相似问题