版权所有,禁止匿名转载;禁止商业使用。
升级xcode6打开以前xcode5工程,发现程序不能定位。代码经检查没有问题,后来发现Ios8对定位处理做了一些调整,工程升级到xcode6编译时需要iOS8 要自己写授权,不然没权限定位。
修改点如下:
1. @interface里:
CLLocationManager *locationManager;
2. 初始化:
locationManager = [[CLLocationManager alloc] init];
3. 调用请求:
if ([[[UIDevice currentDevice] systemVersion] doubleValue] > 8.0) { //设置定位权限 仅ios8有意义 [locationManager requestWhenInUseAuthorization];// 前台定位 // [locationManager requestAlwaysAuthorization];// 前后台同时定位 } [locationManager startUpdatingLocation];
4. 在 info.plist里加入对应的缺省字段 ,值设置为YES(前台定位写上边字段,前后台定位写下边字段)
NSLocationWhenInUseUsageDescription //允许在前台获取GPS的描述 NSLocationAlwaysUsageDescription //允许在前、后台获取GPS的描述