根据文档,需要在使用CoreLocation前调用方法
1
requestWhenInUseAuthorization()
或者
1
requestAlwaysAuthorization()
并在Info.plist中加入两个缺省没有的字段
NSLocationAlwaysUsageDescription
NSLocationWhenInUseUsageDescription
这两个字段没什么特别的意思,就是自定义提示用户授权使用地理定位功能时的提示语。
比如
Hibeacons项目
https://github.com/nicktoumpelis/HiBeacons
中
Supporting Files中
设置
NSLocationAlwaysUsageDescription
value
always ok?
如图
在NATViewController.m中
加一句 [self.locationManager requestAlwaysAuthorization];
- (void)createLocationManager { [self.locationManager requestAlwaysAuthorization]; if (!self.locationManager) { self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; } }
还有另一个例子
<<iBeacons的编程例子>>
http://www.chinaibeacons.com/index.php?a=shows&catid=4&id=20
需要修改
ViewController.m
中的
在新建locationManger之后调用
[self.locationManager requestAlwaysAuthorization];
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Initialize location manager and set ourselves as the delegate self.locationManager = [[CLLocationManager alloc] init]; [self.locationManager requestAlwaysAuthorization]; self.locationManager.delegate = self;
还有就是一定要注意把plist中加上
NSLocationWhenInUseUsageDescription 属性,否则还是不好使
参考
http://blog.csdn.net/xcysuccess3/article/details/39379011