iOS8 经纬度获取 说明

---恢复内容开始---

 

iOS8以前照旧。但是:

iOS8 下经纬度获取需要手动进行注册授权。

具体方法如下:

- (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 {

}
View Code

同时注意还需要在工配置文件下添加下面的属性:(info.plist)

NSLocationWhenInUseUsageDescription = YES

致此  已OK。。运行下看看吧

 

posted @ 2015-01-14 15:40  沙漠浮萍  阅读(172)  评论(0编辑  收藏  举报