定位适配iOS 8

来源:互联网 发布:网民网络素养 编辑:程序博客网 时间:2024/05/16 06:55

iOS 8 定位增加了WhenInUse(使用中可用) 和Always(一直可用)。

1. 对应增加了两个请求权限的方法:

- (void)requestWhenInUseAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);- (void)requestAlwaysAuthorization __OSX_AVAILABLE_STARTING(__MAC_NA, __IPHONE_8_0);

2. Info.plist中增加了两个属性

<key>NSLocationAlwaysUsageDescription</key><string>YES</string><key>NSLocationWhenInUseUsageDescription</key><string>YES</string>

配合代理方法(参考资料1中说是新增的方法,其实不是新增的):

/* *  locationManager:didChangeAuthorizationStatus: *   *  Discussion: *    Invoked when the authorization status changes for this application. */- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status __OSX_AVAILABLE_STARTING(__MAC_10_7,__IPHONE_4_2);


代码中修改:

//iOS 8- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{    switch (status) {        case kCLAuthorizationStatusNotDetermined:            //用户还没有选择是否授权            if ([self.lm respondsToSelector:@selector(requestAlwaysAuthorization)]) {                [self.lm requestAlwaysAuthorization];            }            break;        case kCLAuthorizationStatusAuthorizedAlways:        case kCLAuthorizationStatusAuthorizedWhenInUse:            //有定位权限,开始定位,并计时            [self.delegate gpsStartLocating];            break;        default:            //没有定位权限,提示            [self.delegate gpsLocatedFailed];            break;    } }

参考资料:

http://www.cocoachina.com/bbs/read.php?tid=217107&page=1&toread=1#tpc

http://zhidao.baidu.com/link?url=VcCcvHzH_4OsYr_-9_TsgIQue0N6YuI0awbdkVXjFl70tpNbPqRYu2av08jKsCGK4bsDb-vnI-f_7l_Zm096jd-C6NsKEnJLcSrDIn1henO

0 0
原创粉丝点击