iOS8 经纬度获取 说明
---恢复内容开始---
iOS8以前照旧。但是:
iOS8 下经纬度获取需要手动进行注册授权。
具体方法如下:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
- (void)initForLocation { //_locationManager是一个属性 _locationManager = [[CLLocationManager alloc] init]; [_locationManager setDelegate:self]; _locationManager.desiredAccuracy =kCLLocationAccuracyBest; _locationManager.distanceFilter =1000; [_locationManager startUpdatingLocation]; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8) { //由于IOS8中定位的授权机制改变 // 需要进行手动授权 //获取授权认证 [_locationManager requestAlwaysAuthorization]; [_locationManager requestWhenInUseAuthorization]; } } - (void)locationManagerDidPauseLocationUpdates:(CLLocationManager *)manager { } - (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { } - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { }
同时注意还需要在工配置文件下添加下面的属性:(info.plist)
NSLocationWhenInUseUsageDescription = YES
致此 已OK。。运行下看看吧