iOS 判断定位服务是否开启

-(void)judgeLocationServiceEnabled {

    if ([CLLocationManager locationServicesEnabled] &&

        ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedAlways

         || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse)) {

            //定位功能可用,开始定位

 

//用户从未选择过权限

kCLAuthorizationStatusNotDetermined = 0,

//无法使用定位服务,该状态用户无法改变

kCLAuthorizationStatusRestricted,

//用户拒绝该应用使用定位服务,或者定位服务处于关闭状态

kCLAuthorizationStatusDenied,

//一直开启定位

kCLAuthorizationStatusAuthorizedAlways  

//当使用时开启定位

kCLAuthorizationStatusAuthorizedWhenInUse 

};

        }

    else if ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusDenied){

        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"定位失败........." preferredStyle:UIAlertControllerStyleAlert];

        UIAlertAction *action = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

            

        }];

        [alert addAction:action];

        [self presentViewController:alert animated:YES completion:^{

            

        }];

 

    }

}

posted @ 2016-10-27 13:40  大朵的云彩  阅读(2357)  评论(0编辑  收藏  举报