-(void)requestWhenInUseAuthorization {
    if (![self getUserLocationAuth]) {
        self.locationManagerSystem = [[CLLocationManager alloc]init];
        if ([self.locationManagerSystem respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
            [self.locationManagerSystem requestWhenInUseAuthorization];
        }
    }
}

- (BOOL)getUserLocationAuth {
    BOOL result = NO;
    switch ([CLLocationManager authorizationStatus]) {
        case kCLAuthorizationStatusNotDetermined: //用户没有选择是否要使用定位服务(弹框没选择,或者根本没有弹框)
            break;
        case kCLAuthorizationStatusRestricted: //定位服务授权状态受限制,可能由于活动限制了定位服务,并且用户不能改变当前的权限,这个状态有可能不是用户拒绝的,但是也有可能是用户拒绝的
            break;
        case kCLAuthorizationStatusDenied: //用户在设置中关闭定位功能,或者用户明确的在弹框之后选择禁止定位
            [self openAlertView];
            break;
        case kCLAuthorizationStatusAuthorizedAlways:
            result = YES;
            break;
        case kCLAuthorizationStatusAuthorizedWhenInUse:
            result = YES;
            break;
            
        default:
            break;
    }
    return result;
}

 

Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐