您的位置:首页 > 移动开发

iOS 判断当前APP是否开启定位服务,未开通点击确定进入设置里进行设置

2017-03-13 17:45 676 查看
首先我们要倒入一个官方的头文件

#import <MapKit/MapKit.h>
接下俩   

要遵守协议 <CLLocationManagerDelegate>

接下来便是代码了

 CLAuthorizationStatus status = [CLLocationManagerauthorizationStatus];

 if (kCLAuthorizationStatusDenied == status ||kCLAuthorizationStatusRestricted
== status) {

     //这里是未开通时调用的方法

  [selfcreatOrderAlertView];

 }

-(void)creatOrderAlertView{

    UIAlertView * alert = [[UIAlertViewalloc]
initWithTitle:@"提示"

                                                     message:@"需要访问你当前位置,请打开你的位置服务"

       
af2b
                                            delegate:self

                                           cancelButtonTitle:@"取消"

                                           otherButtonTitles:@"确定",nil];

    [alert show];

}

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

    if (buttonIndex ==0) {//取消

        

    }elseif (buttonIndex
==1){//通过下列方法变进入设置里设置权限

        NSURL *settingsURL = [NSURLURLWithString:UIApplicationOpenSettingsURLString];

        [[UIApplicationsharedApplication]
openURL:settingsURL];

    }

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: