您的位置:首页 > 移动开发 > IOS开发

IOS8 位置服务不启动问题

2014-12-26 15:54 239 查看
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 主要区别为是否在后台可以获取地理位置,具体区别在该方法头文件中有写。

原文地址:http://xujiangtao.com/?p=245
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: