【发布时间】:2015-06-01 11:25:18
【问题描述】:
我无法获取当前位置。我仍然收到错误:
Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
我已经完成了在这里找到的所有操作:
在 iOS 模拟器中重置内容和设置(模拟器中的地图应用程序显示正确的位置)。
在 Xcode 中的 Product>Scheme>Edit 我未标记允许位置模拟(当我标记它时,它模拟例如伦敦)。
我已将 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]; }
有什么我忘记了吗? 谢谢!
【问题讨论】:
标签: ios objective-c location ios-simulator cllocationmanager