CLLocationManager 状态监听

CLLocationManager 自带的代理方法:

/**
 *  定位授权状态改变
 *
 *  @param manager CLLocationManager
 *  @param status  当前状态
 */
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
    switch (status) {
        case kCLAuthorizationStatusNotDetermined:
        {
            // 未处理
            NSLog(@"未处理");
        }
            break;
        case kCLAuthorizationStatusDenied:
        {
            // 判断当前设备是否支持定位, 定位服务是否开启
            if([CLLocationManager locationServicesEnabled])
            {
                NSLog(@"被拒绝");
            } else {
                NSLog(@"定位服务被关闭");
            }
        }
            break;
        case kCLAuthorizationStatusRestricted:
        {
            NSLog(@"受限制");
        }
            break;
        case kCLAuthorizationStatusAuthorizedAlways:
        {
            NSLog(@"前后台定位授权");
        }
            break;
        case kCLAuthorizationStatusAuthorizedWhenInUse:
        {
            NSLog(@"前台定位授权");
        }
          break;
        default:
            break;
    }
}

谢谢~

你可能感兴趣的:(CLLocationManager 状态监听)