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:^{

            

        }];

 

    }

}


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM