我想获取当前位置,但却收到了错误提示。
以下是我的视图控制器代码片段。
- (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.)"
Apple
。如果你将其设置为none
,它将无法工作并抛出此错误。我是无意中这样做的。 - CDM social medias in bio