简体   繁体   English

didFailWithError:错误域= kCLErrorDomain代码= 0“无法完成操作。 (kCLErrorDomain错误0。)“

[英]didFailWithError: Error Domain=kCLErrorDomain Code=0 “The operation couldn’t be completed. (kCLErrorDomain error 0.)”

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.)" 

If you are using the simulator: 如果您使用的是模拟器:

  1. Press command + shift + , in Xcode to open the scheme editor 在Xcode中按command + shift + ,打开方案编辑器
  2. Select the Run scheme 选择“运行”方案
  3. Go to the Options tab 转到“选项”选项卡
  4. Check ✅ Allow Location Simulation 检查✅ Allow Location Simulation
  5. Select a Default Location in the dropdown 在下拉列表中选择默认位置

Selecting None as your Default Location may have caused the problem. 选择“ None作为默认位置可能会导致问题。

  1. Check that you actually have a valid WiFi and 3G connection 检查您确实拥有有效的WiFi和3G连接

    ...if you do, then: ......如果你这样做,那么:

  2. Go to settings and reset your location services 转到设置并重置您的位置服务

  3. Reset your network settings 重置您的网络设置

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上给予负面评价...原谅我,我在那里有点情绪化。

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:的方法是一种非常愚蠢的方式locationManager:didFailWithError: - 谢谢Apple!

Apple Documentation

Try restarting the simulator (assuming that's what you're using). 尝试重新启动模拟器(假设您正在使用它)。

After trying everything else this worked for me. 在尝试了其他一切后,这对我有用。

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...清除所有"iOS Simulator" >> "Reset Content and Settings...

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) (确保按钮为蓝色)

在此输入图像描述

I have the same problem. 我也有同样的问题。 I believe the possible explanations / fixes are covered in this SO post . 我相信这篇SO帖子中涵盖了可能的解释/修复。

Changing the "Location" on the simulator worked for me. 更改模拟器上的“位置”对我有用。

Debug > Location > (Mine was checked None instead of City Bicycle Ride eg) 调试>位置>(我的选中没有,而不是城市自行车骑行例如)

  1. In the simulator go to Settings > General > Reset > Reset Location & Privacy 在模拟器中,转到设置>常规>重置>重置位置和隐私

  2. Quit simulator and run app again 退出模拟器并再次运行应用程序

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. 如果您没有选择,则会出现此错误。

如果你正在使用一个custom location确保你有正确的方式,我已经逆转并浪费了3个小时才意识到...

I have see the problem before,there is a way to solve it,but it can only work one time.If you want to run the project again and you need to repeat the solution each time. 我之前看到过这个问题,有办法解决它,但它只能工作一次。如果你想再次运行项目,你需要每次重复解决方案。

1.In Xcode,Product -> Scheme -> Edit Scheme,then cancel the "Allow Location Simulator". 1.在Xcode,Product - > Scheme - > Edit Scheme中,取消“Allow Location Simulator”。

2.To the iOS Simulator and reset Content and Setting. 2.到iOS模拟器并重置内容和设置。

3.Again to the Xcode,repeat the first step. 3.再与Xcode重复第一步。

4.To the iOS Simulator and reset. 4.到iOS模拟器并重置。 Then it will work. 然后它会工作。

Issues like this can be resolved by setting location as " Apple ". 通过将位置设置为“ Apple ”可以解决此类问题。 At least it works for testing purpose. 至少它适用于测试目的。

  1. I have reseted contents and settings. 我重置了内容和设置。
  2. Removed data from derived data. 从派生数据中删除了数据。
  3. Restarted the Xcode, and Simulator and worked for me. 重新启动Xcode和Simulator并为我工作。

from the answer of @Mem and many others thanks 从@Mem的答案和其他许多人的感谢

For returned devs :) Just select " Debug->Location->Freeway Drive " from the Simulator menu. 对于返回的开发人员:)只需从模拟器菜单中选择“ Debug->Location->Freeway Drive ”。 If still problem then try after doing "Simulator->Reset Content and Settings" form the simulator menu. 如果仍有问题,请在模拟器菜单中执行“模拟器 - >重置内容和设置”后尝试。 This helped me once with the same issue. 这对我有同样的问题帮了我一次。 Some time simulator location is set to " Custom location " due to which its not detecting anything. 某些时间模拟器位置设置为“ Custom location ”,因为它没有检测到任何内容。

Try in device. 尝试使用设备。 Sometimes simulator fails to take your location. 有时模拟器无法占据您的位置。

Go to home in simulator 在模拟器中回家

home ->Settings ->Privacy ->Locations -> select the app and choose always 主页 - >设置 - >隐私 - >位置 - >选择应用程序并始终选择

添加权限时隐私 - 在info.plist中使用时的位置使用说明它已经解决了

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误域=kCLErrorDomain 代码=2“操作无法完成。(kCLErrorDomain 错误 2。)” - Error Domain=kCLErrorDomain Code=2 "The operation couldn’t be completed. (kCLErrorDomain error 2.)" 更新位置时出错 操作无法完成。 (kCLErrorDomain 错误 0。) - Error while updating location The operation couldn’t be completed. (kCLErrorDomain error 0.) kCLErrorDomain Code=8 &quot;操作无法完成。 - kCLErrorDomain Code=8 "The operation couldn’t be completed. 位置管理器错误:操作无法完成。 (kCLErrorDomain错误0。) - Location Manger Error: The operation couldn’t be completed. (kCLErrorDomain error 0.) CLGeocoder 返回错误:操作无法完成。 (kCLErrorDomain 错误 8。) - CLGeocoder returning error : The operation couldn’t be completed. (kCLErrorDomain error 8.) CLLocationManager: allowDeferredLocationUpdates - 不断获取操作无法完成。 (kCLErrorDomain 错误 11。) - CLLocationManager: allowDeferredLocationUpdates - keep getting The operation couldn’t be completed. (kCLErrorDomain error 11.) 错误:该操作无法完成。 (LaunchServicesError错误0。) - Error: The operation couldn’t be completed. (LaunchServicesError error 0.) Error Domain = NSCocoaErrorDomain代码= 512“该操作无法完成。该操作无法完成。是一个目录 - Error Domain=NSCocoaErrorDomain Code=512 "The operation couldn’t be completed.The operation couldn’t be completed. Is a directory 错误:错误域= NSCocoaErrorDomain代码= 3840“该操作无法完成。 - Error:Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. iOS 8 - 无法获取当前位置,错误域= kCLErrorDomain代码= 0 - iOS 8 - Can't get current location, Error Domain=kCLErrorDomain Code=0
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM