iOS 8 - 无法获取当前位置,错误域= kCLErrorDomain代码= 0 [英] iOS 8 - Can't get current location, Error Domain=kCLErrorDomain Code=0

查看:171
本文介绍了iOS 8 - 无法获取当前位置,错误域= kCLErrorDomain代码= 0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取当前位置时遇到问题。我仍然收到错误:

I've problem with getting my current location. I still getting error:

Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"

我已经做了我在这里找到的所有事情:

I already did everything that I found here:

重置iOS模拟器中的内容和设置(模拟器中的地图应用程序显示正确的位置)。

在Xcode中的产品>方案>编辑我没有标记允许位置模拟(当我标记它时,它模拟例如伦敦)。

我已将NSLocationWhenInUseUsageDescription添加到我项目中的Info.plist文件中(App要求获取位置权限,我可以在iOS模拟器的设置中看到它们)。

我打开了Wi-Fi连接(就像我说的定位服务在Safari,地图甚至iOS模拟器中的地图中工作正常)。

Reset content and settings in iOS Simulator (map application in simulator shows correct location).
In Xcode at Product>Scheme>Edit I unmarked Allow Location Simulation (when I mark it,It simulate e.g. London).
I have added NSLocationWhenInUseUsageDescription to Info.plist file in my project (App asks for Location permissions and I can see them in Settings in iOS simulator).
I have Wi-Fi connection turned on (like I said location services works fine in Safari, Maps or even Maps in iOS Simulator).

-(void)viewDidLoad    {
       [super viewDidLoad];
       self.locationManager = [[CLLocationManager alloc] init];

       self.locationManager.delegate = self;
       if(IS_OS_8_OR_LATER){
           NSUInteger code = [CLLocationManager authorizationStatus];
           if (code == kCLAuthorizationStatusNotDetermined && ([self.locationManager    respondsToSelector:@selector(requestWhenInUseAuthorization)])) {

               if([[NSBundle mainBundle] objectForInfoDictionaryKey:@"NSLocationWhenInUseUsageDescription"]) {
                   [self.locationManager  requestWhenInUseAuthorization];
               } else {
                   NSLog(@"Info.plist does not contain NSLocationAlwaysUsageDescription or    NSLocationWhenInUseUsageDescription");
               }
           }
       }
       [self.locationManager startUpdatingLocation];
       [self.FirstMap setShowsUserLocation:YES];    }

   - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error    {
       NSLog(@"didFailWithError: %@", error);
       UIAlertView *errorAlert = [[UIAlertView alloc]
                                  initWithTitle:@"Error" message:@"Failed to Get Your Location" delegate:nil    cancelButtonTitle:@"OK" otherButtonTitles:nil];
       [errorAlert show];    }

我有什么遗忘的吗?
谢谢!

Is there something that i forgot about? Thanks!

推荐答案

我想你可能需要首先阅读这个帖子,因为它在很大程度上是重叠的。

I guess maybe you need to read this thread first as it's largely overlapped.

位置管理器错误:(KCLErrorDomain错误0)

但无论如何,我测试了你的代码并得到了与你报告的相同的错误。然后我改变了模拟配置。具体来说,在模拟器中,我单击调试 - >位置 - >自定义位置...并输入一个坐标,我可以定期接收位置事件(以每秒每个样本的速度。)所以可能问题不是从代码但来自模拟器本身。希望我的回答有所帮助。

But anyway, I tested your code and got the same error as you reported. Then I change the simulation configuration. To be specific, in the simulator, I clicked Debug -> Location -> Custom Location... and enter a coordinate, and I can periodically receive location events (at a speed of every sample per second.) So maybe the problem is not from the code but from the simulator itself. Hope my answer helps.

更新

我想我误解了你的问题。你想要的是自动获取你在模拟器中的当前位置。我担心xcode中没有这样的功能,相反,你需要使用添加gpx文件到项目,这比使用自定义位置更加重要。但我的意思是,如果你已经成功找到了正确的位置,为什么它让你无法从模拟器中获得正确的当前位置,或者替代方案,也许你可以在手机上进行测试?

I guess I misunderstood your question. What you want is to "automatically" get your current location in simulator. I'm afraid there's no such feature in xcode, instead, you need to use "add gpx file to project", which is even more work than using customized location. But I mean, if you've successfully got correct locations, why it bothers you to get the correct current location from the simulator, or alternative, maybe you can test on phone?

这篇关于iOS 8 - 无法获取当前位置,错误域= kCLErrorDomain代码= 0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆