iOS地理定位
2015-07-22 10:30
357 查看
-引入头文件
-声明变量
-实现代理方法
-初始化locationManager
-实现代理方法
-支持iOS8
添加:NSLocationWhenInUseUsageDescription, NSLocationAlwaysUsageDescription
代码下载:CLLocationManager
#import <CoreLocation/CoreLocation.h>
-声明变量
@property (nonatomic, strong)CLLocationManager *locationManager;
-实现代理方法
@interface LocationTool : NSObject <CLLocationManagerDelegate>
-初始化locationManager
- (instancetype)init { self = [super init]; if (self) { _locationManager = [[CLLocationManager alloc]init]; _locationManager.delegate = self; _locationManager.desiredAccuracy = kCLLocationAccuracyBest; _locationManager.distanceFilter = kCLDistanceFilterNone; if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) { [_locationManager requestWhenInUseAuthorization]; } } return self; }
-实现代理方法
#pragma mark CLLocationManagerDelegate -(void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error{ NSLog(@"定位出错"); } -(void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations{ NSLog(@"定位成功"); } -(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{ switch (status) { case kCLAuthorizationStatusNotDetermined: //用户还没有被请求获取授权 if ([_locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [_locationManager requestWhenInUseAuthorization]; } NSLog(@"kCLAuthorizationStatusNotDetermined"); break; default: break; } }
-支持iOS8
添加:NSLocationWhenInUseUsageDescription, NSLocationAlwaysUsageDescription
代码下载:CLLocationManager
相关文章推荐
- SDWebImage内存缓存 磁盘缓存
- iOS-响应链机制
- iOS 各种控件默认高度
- iOS内存管理--nonatomic,assign,copy,retain
- IOS开发进阶
- 关于iOS的Block类型截获自动变量值
- MMDrawerController抽屉效果类库
- iOS原生二维码扫描(可以指定有效区域)
- 服务器报错:Unable to load LSI Corporation MPT BIOS
- ios设备唯一标识获取策略
- iOS开发OC基础:Xcode中常见英文总结,OC常见英文错误
- ios-单元测试
- iOS开发 - Core Animation 核心动画
- IOS计算字符串尺寸
- CSDN iOS安全攻防专栏
- iOS开发多线程同步
- iOS开发 - CALayer图层
- iOS接收null的处理方法
- iOS应用安全开发,你不知道的那些事
- iOS-字符串拼接