【发布时间】:2011-08-27 08:09:45
【问题描述】:
我想获取当前位置,但我得到了一个错误。
这是我的视图控制器的 sn-p。
- (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.)"
【问题讨论】:
-
您可以使用 google api 作为替代方案。在这里参考我的答案stackoverflow.com/a/40670608/2033377
-
goto 模拟器 -> 功能 -> 位置 ->
Apple。如果您将其设置为none,它将无法正常工作并抛出此错误。我是意外这样做的
标签: ios iphone core-location cllocationmanager cllocation