iOS8 定位补充
iOS 8定位補充
iOS 8定位需要修改2個地方
1.info.plist文件中添加NSLocationAlwaysUsageDescription:描述信息
從iOS 8開始,用戶定位分兩種情況 總是使用用戶位置:NSLocationAlwaysUsageDescription 使用應用時定位:NSLocationWhenInUseDescription2.在CLLocationManager中調用
- (void)requestAlwaysAuthorization
- (void)requestWhenInUseAuthorization
?
#import "ViewController.h" #import <CoreLocation/CoreLocation.h>@interface ViewController () <CLLocationManagerDelegate>@property(nonatomic,strong)CLLocationManager *mgr;@end@implementation ViewController- (void)viewDidLoad {[super viewDidLoad];[self.mgr startUpdatingLocation];// 如果是iOS8,需要請求授權方式(進行判斷,否則在iOS7會崩潰,需要先在info.plist中配置)// 1.通過判斷系統判斷來確定是否需要請求requestAlwaysAuthorization授權 // if ([UIDevice currentDevice].systemVersion.floatValue >= 8.0) { // [self.mgr requestAlwaysAuthorization]; // }// 2.通過判斷是否有該方法來判斷是否需要請求requestAlwaysAuthorization授權if ([self.mgr respondsToSelector:@selector(requestAlwaysAuthorization)]) {[self.mgr requestAlwaysAuthorization];} }- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {NSLog(@"獲取到用戶的位置"); }- (CLLocationManager *)mgr {if (_mgr == nil) {_mgr = [[CLLocationManager alloc] init];_mgr.delegate = self;}return _mgr; }@end?
轉載于:https://www.cnblogs.com/HJiang/p/4345060.html
總結
- 上一篇: T-40轻型水陆坦克
- 下一篇: 一艘轮船在水速为3千米&#47;