一、
问题描述:使用xcode6和ios8开发定位应用时,发现执行操作之后,不会调用到定位之后的delegate方法中。查看了一下手机上对应用的定位权限界面,发现我的应用的访问用户的地理位置的权限是空的,即使设置了定位权限依然不会生效。当查阅了相关资料以后,得到如下解决方案:
解决方案:
step1:
在info.plist里加入:
NSLocationWhenInUseDescription,允许在前台获取GPS的描述
NSLocationAlwaysUsageDescription,允许在后台获取GPS的描述
最终如下图所示:
step2:
1.@interface里:
CLLocationManager *locationManager;
2. 初始化:
locationManager = [[CLLocationManager alloc]init];
3. 调用请求:
// 判断是否iOS8
if([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]){
[self.locationManagerrequestAlwaysAuthorization]; // 永久授权
[self.locationManagerrequestWhenInUseAuthorization]; //使用中授权
}
[self.locationManager startUpdatingLocation];
添加以上内容之后即可以进行定位服务,百度地图和高德地图测试可用。
参考资料&扩展阅读
http://stackoverflow.com/questions/24062509/location-services-not-working-in-ios-8
http://stackoverflow.com/questions/24874997/core-location-not-working-in-ios-8