我最近问了这个问题,不知道iOS 9中对CL所做的更改。我正在尝试存储用户的当前位置,我已经更改了代码以反映iOS 9中的新委托方法,但didUpdateLocations仍然无法访问。
这是我最初问题的链接:纬度&未检索到的经度
我更新的代码:
视图将出现
- (void)viewWillAppear:(BOOL)animated{
manager = [[CLLocationManager alloc] init];
manager.delegate = self;
if ([manager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
[manager requestWhenInUseAuthorization];
}
[manager startUpdatingLocation];
}
didUpdateLocations
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations{
NSLog(@"Location: %@", locations);
CLLocation *currentLocation = locations.lastObject;
if (currentLocation != nil) {
float latitude = currentLocation.coordinate.latitude;
float longitude = currentLocation.coordinate.longitude;
NSLog(@"dLongitude : %f", longitude);
NSLog(@"dLatitude : %f", latitude);
}
else{ NSLog(@"ERROR");
}
}
检查
authorizationStatus and startUpdatingLocation
和
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
您还可以进入设置->隐私->位置服务(打开)->选择您的应用程序并在使用时进行选择。