Error Domain=kCLErrorDomain Code=0 "The operation couldn’t be completed. (kCLErrorDomain error 0.)"
我已经按照以下步骤完成了所有操作:
在iOS模拟器中重置内容和设置(模拟器中的地图应用程序显示正确的位置)。
在Xcode中,转到Product>Scheme>Edit,取消勾选Allow Location Simulation(当我勾选它时,它会模拟例如伦敦的位置)。
在我的项目的Info.plist文件中添加NSLocationWhenInUseUsageDescription(应用程序请求位置权限,并且我可以在iOS模拟器的设置中看到它们)。
我已经打开了Wi-Fi连接(就像我说的,位置服务在Safari、Maps甚至iOS模拟器中的Maps中都可以正常工作)。
-(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]; }
我有没有忘记什么东西? 谢谢!