---
title: "ios8的定位，蓝牙与ios7的区别"
author: "haoningabc"
date: "2014-10-06T23:27:10Z"
tags: ["iOS"]
categories: ["移动开发"]
slug: "ios8-ios7"
draft: false
lastmod: "2014-10-06T23:47:52Z"
id: 2124923
url: "https://haoningabc.iteye.com/blog/2124923"
---

以前程序的地理定位功能在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?
如图
![](http://dl2.iteye.com/upload/attachment/0101/7253/3b7f5988-bde6-35c4-a00f-d13093f70338.jpg)

在NATViewController.m中
加一句<span style="color:red">;</span>

```java
- (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之后调用
<span style="color:red">;</span>

```java

 - (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中加上
<span style="color:red">NSLocationWhenInUseUsageDescription 属性，否则还是不好使</span>

参考
http://blog.csdn.net/xcysuccess3/article/details/39379011