Xcode6 ios8的定位新特性
2014-12-13 21:11
239 查看
在 iOS 7 以及更早之前的版本,MapView 显示使用者位置不需要调用授权方法,現在都要了。
在 iOS 8 上编译会出現以下 log :
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
首先必須要修改 info.plist
新增 key值 NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription
Value值为要出現在屏幕上的字,终于可以自定义要显示的信息了!但也可以留白。
两者的差异仅在前者只有使用中才会定位,后者是在背景也会持续定位。
接著修改代码,第5行是重点
另外授权部分也要修改,注意4,5行的差异
上面那行是 iOS 8 以上,第二行是 iOS 7 以下,因为kCLAuthorizationStatusAuthorized 在 iOS 8 完全不能使用。
別的地方
在 iOS 8 上编译会出現以下 log :
Trying to start MapKit location updates without prompting for location authorization. Must call -[CLLocationManager requestWhenInUseAuthorization] or -[CLLocationManager requestAlwaysAuthorization] first.
首先必須要修改 info.plist
新增 key值 NSLocationWhenInUseUsageDescription 或 NSLocationAlwaysUsageDescription
Value值为要出現在屏幕上的字,终于可以自定义要显示的信息了!但也可以留白。
两者的差异仅在前者只有使用中才会定位,后者是在背景也会持续定位。
接著修改代码,第5行是重点
locationManager = [[CLLocationManager alloc] init]; locationManager.delegate = self; locationManager.desiredAccuracy=kCLLocationAccuracyBest; if([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) { [locationManager requestWhenInUseAuthorization]; } [locationManager startUpdatingLocation];
另外授权部分也要修改,注意4,5行的差异
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status { if ( ([locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorizedWhenInUse) || (![locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)] && status != kCLAuthorizationStatusNotDetermined && status != kCLAuthorizationStatusAuthorized) ) { NSString *message = @"您的手机目前并未开启定位服务,如欲开启定位服务,请至设置->隐私->定位服务,开启本程序的定位服务功能"; UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"无法定位" message:message delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil]; [alertView show]; }else { [locationManager startUpdatingLocation]; } }
上面那行是 iOS 8 以上,第二行是 iOS 7 以下,因为kCLAuthorizationStatusAuthorized 在 iOS 8 完全不能使用。
別的地方
CLAuthorizationStatus status = [CLLocationManager authorizationStatus]; if (status == kCLAuthorizationStatusAuthorizedWhenInUse || status == kCLAuthorizationStatusAuthorized) { // 开始定位 }else { // 显示警告 }
相关文章推荐
- 关于ios8定位服务的新增特性
- Xcode6下iOS8地图无法定位问题Trying to start MapKit location updates without prompting for location authorizat
- Xcode6 iOS8 使用地图无法定位
- Xcode6编译IOS8无法定位的问题解决
- xcode6打开以前工程在Ios8系统无法定位解决方案
- Xcode6编译IOS8无法定位的问题解决
- day14 HTML 表单标签 CSS 基本的用法 CSS 高级用法--定位 CSS 中的基本单位 CSS 3 新特性
- iOS8 【xcode6中添加pch全局引用文件】
- 开发者所需要知道的 iOS8 SDK 新特性
- XCode6中定位失败的解决办法
- iOS8定位问题
- 升级到XCode6后,iOS8里设置tableview的setSeparatorInset:UIEdgeInsetsZero不起作用的解决办法
- iOS8中使用CoreLocation定位
- iOS 关于iOS8地图定位问题
- iOS8定位与地图
- IOS8 通知中心(Notification Center)新特性
- iOS8 沙盒路径变化特性
- iOS8中webview添加定位功能
- iOS8新特性扩展(Extension)应用之二——分享插件
- ios8及Xcode6下启动界面配置