首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >didFailWithError: Error Domain=kCLErrorDomain Code=0“无法完成操作。(kCLErrorDomain错误0。)”

didFailWithError: Error Domain=kCLErrorDomain Code=0“无法完成操作。(kCLErrorDomain错误0。)”
EN

Stack Overflow用户
提问于 2011-05-17 23:10:45
回答 12查看 87K关注 0票数 83

我想得到当前的位置,但是我得到了一个错误。

这是我的视图控制器的一个片段。

代码语言:javascript
运行
复制
- (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:被调用,并打印以下内容:

代码语言:javascript
运行
复制
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)" 
EN

回答 12

Stack Overflow用户

发布于 2014-09-10 11:25:26

只需忽略此错误并等待更多更新或其他错误。

位置管理器的文档说这个错误是暂时的。它会让您知道它未能立即检索到某个位置,但它会继续尝试。在这种情况下,您可以忽略错误并等待新事件。这是使用名为locationManager:didFailWithError:的方法的一种非常愚蠢的方式--谢谢苹果!

Apple Documentation

票数 24
EN

Stack Overflow用户

发布于 2013-12-19 00:24:13

尝试重新启动模拟器(假设您正在使用该模拟器)。

在尝试了其他方法之后,这对我来说是有效的。

票数 19
EN

Stack Overflow用户

发布于 2015-03-24 01:46:15

我在模拟器上得到了这个错误。单击“调试”面板中的“位置”按钮并设置一个位置,为我修复了这个问题。(确保按钮为蓝色)

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6032976

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档