iOS 8 – 无法获取当前位置,错误域= kCLErrorDomain代码= 0

我有问题得到我的当前位置。 我仍然收到错误:

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

我已经做了我在这里find的所有东西:

重置iOS模拟器中的内容和设置(模拟器中的地图应用程序显示正确的位置)。
在Xcode的产品>计划>编辑我未标记的允许位置模拟(当我标记它,它模拟例如伦敦)。
我已经添加NSLocationWhenInUseUsageDescription Info.plist文件在我的项目(应用程序要求的位置的权限,我可以看到他们在设置在iOS模拟器)。
我打开了Wi-Fi连接(就像我说的位置服务在Safari,地图,甚至在iOS模拟器中的地图一样正常工作)。

 -(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]; } 

有什么我忘了吗? 谢谢!

我想也许你需要先阅读这个线程,因为它很大程度上是重叠的。

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

但无论如何,我testing了你的代码,并得到了你所报告的同样的错误。 然后我改变模拟configuration。 具体来说,在模拟器中,我单击debugging – >位置 – >自定义位置…并input一个坐标,我可以定期接收位置事件(以每秒样本的速度)。所以也许问题不是从代码,但从模拟器本身。 希望我的回答有帮助。

UPDATE

我想我误解了你的问题。 你想要的是“自动”获取您的模拟器中的当前位置。 恐怕xcode中没有这样的function,相反,你需要使用“添加gpx文件到项目”,这比使用自定义的位置更多的工作。 但是我的意思是,如果你已经成功地获得了正确的位置,为什么它会困扰你从模拟器中获得正确的当前位置,或者你可以在手机上testing吗?

在iOS 8中,您必须首先获得用户的许可才能访问iOS 7中无法访问本地的位置

 if CLLocationManager.locationServicesEnabled() { if self.manager.respondsToSelector("requestWhenInUseAuthorization") { manager.requestWhenInUseAuthorization() } else { startUpdatingLocation() } } 

从这个链接更多的帮助http://nshipster.com/core-location-in-ios-8/

检查互联网连接。 如果连接正常,先进入Xcode日志栏并设置“不要模拟位置”。 然后select模拟器菜单>debugging>位置>设置自定义或select任何。