Luc*_*uca 79 iphone core-location cllocationmanager cllocation ios
我想获取当前位置,但我得到一个错误.
这是我的视图控制器的片段.
- (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);
}
Run Code Online (Sandbox Code Playgroud)
我期待委托方法locationManager:didUpdateLocations:被调用,但只是locationManager:didFailWithError:被调用,并打印出来:
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
Run Code Online (Sandbox Code Playgroud)
sil*_*eep 133
如果您使用的是模拟器:
command + shift + ,Xcode打开方案编辑器Allow Location Simulation选择None默认位置可能会导致问题.
小智 105
检查您确实拥有有效的WiFi和3G连接
......如果你这样做,那么:
转到设置并重置您的位置服务
这应该解决这个问题.它与设备/网络相关而非应用相关.这很烦人,特别是如果你的应用程序依赖于位置服务而且设备只是WiFi而且人们在AppStore上给予负面评价...原谅我,我在那里有点情绪化.
Ray*_*ite 22
只需忽略此错误并等待更多更新或其他错误.
位置管理员的文档说这个错误是暂时的.它让你知道它无法立即检索一个位置,但它继续尝试."在这种情况下,您可以简单地忽略错误并等待新事件." 使用名为的方法是一种非常愚蠢的方式locationManager:didFailWithError:- 谢谢Apple!
| 归档时间: |
|
| 查看次数: |
80143 次 |
| 最近记录: |