IOS 系统定位提示完毕后 提示用户去开启定位权限

当用户选择了系统不开启定位提示后,在此处可以然后去提示用户开启定位权限。


当定位失败时,通过定位失败的code来判断是否需要再次弹出提示用户定位的对话框

http://bbs.yusian.com/thread-10617-1-1.html

Code=0说明没有位置信息

Code=1说明是系统授权问题  


- (void)mapLocationDidFailWithError:(NSError *)error
{
    NSLog(@"----%@",error);
    
    if (error.code == 1)
    {
        if([[NSUserDefaults standardUserDefaults] boolForKey:@"EachTimeAppStart"])
        {
            //判断定位服务权限是否开通
            [self initCLLocationManager];
            [[NSUserDefaults standardUserDefaults] setBool:NO forKey:@"EachTimeAppStart"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
    }
}

- (void)initCLLocationManager
{
    BOOL enable=[CLLocationManager locationServicesEnabled];
    NSInteger status=[CLLocationManager authorizationStatus];
    if(!enable || status<3)
    {
        if ([[UIDevice currentDevice].systemVersion floatValue] >= 8)
        {
            CLLocationManager  *locationManager = [[CLLocationManager alloc] init];
            [locationManager requestAlwaysAuthorization];
            [locationManager requestWhenInUseAuthorization];
        }
        
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"打开定位开关"
                                                            message:@"定位服务未开启,请进入系统[设置]> [隐私] > [定位服务]中打开开关,并允许使用定位服务"
                                                           delegate:self
                                                  cancelButtonTitle:nil
                                                  otherButtonTitles:@"取消",@"立即开启", nil];
        alertView.tag = ALERTTAGNUMBER;
        [alertView show];
        
    }
}


  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值