如何弹出跳转到开启定位的设置

使用定位功能时,如果没有开启定位功能,如何可民提醒用户,并提示用户进入系统设置界面

如果在编码中加入了如下判断语句“[CLLocationManager locationServicesEnabled]”,则不会出现可以进入系统设置视图的提示(图1),此时应该由编码人员自定义提示(图2)。

    // 判断是否开启定位服务

    if ([CLLocationManager locationServicesEnabled])

    {

        // do something

        

        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"定位服务未开启"

                                                        message:@"请在系统设置中开启定位服务(设置>隐私>定位服务>开启xx"

                                                       delegate:self

                                              cancelButtonTitle:@"知道了"

                                              otherButtonTitles:nil, nil];

        [alert show];

    }



(图1)


(图2)


图1的系统提示不管在哪个系统版本均会在应用第一次使用时进行提示。

如果用户想通过编码实现跳转,则只有在iOS5.0以下系统才可实现,详细编码如下所示:

    // 判断是否开启定位服务

    if ([CLLocationManager locationServicesEnabled])

    {

        // do something

        if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]])

        {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提醒"

                                                            message:@"定位服务未开启,请打开定位服务功能。"

                                                           delegate:self

                                                  cancelButtonTitle:@"设置"

                                                  otherButtonTitles:@"取消", nil];

            [alert show];

        }

        else

        {

            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"温馨提醒"

                                                            message:@"定位服务未开启,请打开定位服务功能。"

                                                           delegate:self

                                                  cancelButtonTitle:@"取消"

                                                  otherButtonTitles:@"确定", nil];

            [alert show];

        }

    }


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

{

    if (buttonIndex == 0)

    {

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"]];

    }

}


转载于:https://my.oschina.net/potato512/blog/647835

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值