2015-12-11 76 views
-1

我最近问这个问题,不知道在iOS 9中对CL所做的更改。我试图存储用户的当前位置,并且已更改我的代码以反映iOS 9中的新委托方法,但didUpdateLocations仍然没有达到。CoreLocation iOS9存储坐标

这里是链接到我原来的问题:Latitude & Longitude Not Retrieved

而我更新的代码:

viewWillAppear中

- (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"); 
    } 

} 

回答

1

支票

authorizationStatus and startUpdatingLocation 

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations 

- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status 

,你也可以去设置 - >隐私 - >定位服务(打开) - >选择乌尔应用程序,同时使用选择。

+0

我的位置服务已打开,但我没有看到我列出的应用程序 – themotjuste

+0

您是否在plist中添加了密钥? – vaibby

+0

在Info.plist中添加NSLocationAlwaysUsageDescription或NSLocationWhenInUseUsageDescription项,并在提示中显示一条消息。添加这些将解决您的问题。 – vaibby