`
haoningabc
  • 浏览: 1444515 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

ios8的定位,蓝牙与ios7的区别

ios 
阅读更多
  以前程序的地理定位功能在iOS8 版上不能工作了(也可能其它beta版也不工作),查询GPS授权情况,返回的是CLAuthorizationStatus.NotDetermined,意思是授权状态未定。

  根据文档,需要在使用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
  • 大小: 90.8 KB
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics