IOS App定位服务在IOS7中正常,IOS8中打开MapKit
时没有弹出位置验证提示并且didUpdateLocations代理方法也不调用。
原因:
在IOS8中新增了 requestAlwaysAuthorization 和 requestWhenInUseAuthorization 方法,需要将他们添加到info.plist文件中。但是xcode6没有默认添加,用编辑器打开info.plist文件,添加
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
<key>NSLocationAlwaysUsageDescription</key>
<string></string>
string标签中间根据需要添加相应的提示文字。
然后调用打开地址位置时 如下
#define IS_OS_8_OR_LATER ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0)
//In ViewDidLoad
if(IS_OS_8_OR_LATER) {
[self.locationManager requestAlwaysAuthorization];
}
[self.locationManager startUpdatingLocation];
requestAlwaysAuthorization 与 startUpdatingLocation 主要区别为是否在后台可以获取地理位置,具体区别在该方法头文件中有写。