ios didFailWithError: Error Domain=kCLErrorDomain Code=0 “操作无法完成。(kCLErrorDomain 错误 0。)”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6032976/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
提问by Luca
I want to get the current location, but instead I get an error.
我想获取当前位置,但出现错误。
This is a snippet of my view controller.
这是我的视图控制器的片段。
- (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);
}
I'm expecting the delegate method locationManager:didUpdateLocations:
to get called, but instead, only locationManager:didFailWithError:
gets called, and prints this:
我期待委托方法locationManager:didUpdateLocations:
被调用,但相反,只locationManager:didFailWithError:
被调用,并打印:
didFailWithError: Error Domain=kCLErrorDomain Code=0 "The operation couldn't be completed. (kCLErrorDomain error 0.)"
回答by sKhan
If you are using the simulator:
如果您使用模拟器:
- Press
command + shift + ,
in Xcode to open the scheme editor - Select the Run scheme
- Go to the Options tab
- Check ?
Allow Location Simulation
- Select a Default Location in the dropdown
command + shift + ,
在 Xcode 中按下以打开方案编辑器- 选择运行方案
- 转到选项选项卡
- 查看 ?
Allow Location Simulation
- 在下拉菜单中选择一个默认位置
Selecting None
as your Default Location may have caused the problem.
选择None
作为您的默认位置可能会导致问题。
回答by MeM
Check that you actually have a valid WiFi and 3G connection
...if you do, then:
Go to settings and reset your location services
- Reset your network settings
检查你确实有一个有效的WiFi和3G连接
...如果你这样做,那么:
转到设置并重置您的位置服务
- 重置网络设置
This should take care of that issue. It is device/network related not app related. It's annoying especially if your app is dependent on location services and the device is WiFi only and people give negative ratings on the AppStore... Pardon me, I'm getting a bit emotional there.
这应该解决这个问题。它与设备/网络相关,与应用程序无关。这很烦人,尤其是如果您的应用程序依赖于位置服务并且设备仅支持 WiFi 并且人们在 AppStore 上给出负面评价...请原谅我,我在那里有点情绪化。
回答by Ray Lillywhite
Simply ignore this error and wait for more updates or a different error.
只需忽略此错误并等待更多更新或其他错误。
The docs for the location manager say that this error is temporary. It's letting you know that it failed to immediately retrieve a location, but it continues to try. "In such a situation, you can simply ignore the error and wait for a new event." Which is a really boneheaded way to use a method named locationManager:didFailWithError:
- Thanks Apple!
位置管理器的文档说这个错误是暂时的。它让您知道它未能立即检索位置,但它会继续尝试。“在这种情况下,您可以简单地忽略错误并等待新事件。” 这是使用名为locationManager:didFailWithError:
- 谢谢苹果的方法的一种非常愚蠢的方法!
回答by Ian
Try restarting the simulator (assuming that's what you're using).
尝试重新启动模拟器(假设这是您正在使用的)。
After trying everything else this worked for me.
在尝试了其他一切之后,这对我有用。
回答by Brandon O'Rourke
A restart of the simulator didn't work for me.
模拟器的重启对我不起作用。
I had to clear everything via
"iOS Simulator" >> "Reset Content and Settings...
.
我必须通过
"iOS Simulator" >> "Reset Content and Settings...
.
回答by rounak
I was getting this error on the simulator. Clicking the location button in the debugging panel and setting a location fixed the issue for me. (Ensure that the button is blue)
我在模拟器上收到此错误。单击调试面板中的位置按钮并设置位置为我解决了问题。(确保按钮为蓝色)
回答by Andy Milburn
I have the same problem. I believe the possible explanations / fixes are covered in this SO post.
我也有同样的问题。我相信可能的解释/修复包含在这篇 SO 帖子中。
回答by Raphael Onofre
Changing the "Location" on the simulator worked for me.
更改模拟器上的“位置”对我有用。
Debug > Location > (Mine was checked None instead of City Bicycle Ride e.g.)
调试 > 位置 >(我的被选中 None 而不是 City Bicycle Ride 例如)
回答by Adam Johns
In the simulator go to Settings > General > Reset > Reset Location & Privacy
Quit simulator and run app again
在模拟器中转到设置 > 常规 > 重置 > 重置位置和隐私
退出模拟器并再次运行应用程序
回答by Rodrigo Gonzalez
Assuming that you are using the simulator, you can to Debug -> Location
and set a location.
假设您正在使用模拟器,您可以Debug -> Location
设置一个位置。
If you have none selected you will have this error.
如果您没有选择,则会出现此错误。