ITeye博客

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

haoningabc · 2014-10-06 23:27 · ios · ibeacons · 移动开发 · iOS · Markdown

以前程序的地理定位功能在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中 加一句;

- (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之后调用 ;


 - (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

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。