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