iOS地图定位设置问题详解

来源:互联网 发布:西直门桥设计数据 编辑:程序博客网 时间:2024/05/22 06:26
在IOS8中定位功能新增了两个方法:
- (void)requestWhenInUseAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
- (void)requestAlwaysAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);
这两个新增的方法导致之前写的程序,在iOS8运行会出现定位功能无法正常使用!


正确让ios8定位的方法来了:
1.在Info.plist表里面添加两个变量
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
(这两个字段没什么特别的意思,就是自定义提示用户授权使用地理定位功能时的提示语)


这里需要注意的是:很多小朋友加字段以后不记得吧value写为 “YES”,不写YES也是不行的喔~


2.添加代码:
CLLocationManager *locationManager = [[CLLocationManager alloc]init]; locationManager.delegate = self;  
[locationManager requestAlwaysAuthorization];  
locationManager.desiredAccuracy = kCLLocationAccuracyBest;  
locationManager.distanceFilter = kCLDistanceFilterNone;  
[locationManager startUpdatingLocation];


调用代理:
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {  
switch (status) {  
case kCLAuthorizationStatusNotDetermined:  
if ([locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) { [locationManager requestWhenInUseAuthorization];  
}  
break;  
default:  
break;  
}
}
3.这样就可以打开地图定位功能了!

0 0
原创粉丝点击