ios - 我如何提示用户打开位置服务,即转到设置→隐私→位置服务

标签 ios settings cllocationmanager

下面的代码不能再工作了,我们能做什么

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

以下适用于转到设置 → 您的应用程序 → 位置 但我想访问转到设置 → 隐私 → 定位服务

        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

我遇到了和下面问题一样的问题

Open Settings app from another app programmatically in iPhone

最佳答案

如果用户不打开定位服务,我会使用此代码

 - (void)locationManager:(CLLocationManager *)manager
   didFailWithError:(NSError *)error {
     if ([[error domain] isEqualToString: kCLErrorDomain] && [error code] == kCLErrorDenied) {
       // The user denied your app access to location information.

       UIAlertView* alert=[[UIAlertView alloc] initWithTitle:@"This app does not have access to Location" message:@"You can enable access in Settings" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:@"Settings", nil];
       alert.delegate = self;
       [alert show];
     }


    NSLog(@"%@", error.description);
}

并在此代码中 UIAlertView 中处理 Settings 按钮:

- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
   NSLog(@"buttonIndex:%d",buttonIndex);

   if (buttonIndex == 1) {
       [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
   }
}

关于ios - 我如何提示用户打开位置服务,即转到设置→隐私→位置服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428242/

相关文章:

java - 在 java 中加载 Web 应用程序特定配置和设置的首选方法是什么

ios - 让一个非常简单的 Swift CoreLocation 示例工作

iphone - CLLocationManger 向已分配实例发送消息

ios - 如何将数据从一个 UIView 传递到子 UIView?

ios - 如何以编程方式查找 swift 版本?

ios - 我如何在 iOS swift 中制作登录屏幕的单元测试用例

IOS:如何在用户拒绝时获取 CLLocationManager 警报

ios - 下载图像后重新加载 UITableView 行(使用 MVVM)

settings - 如何隐藏括号编辑器中的底部信息面板(状态栏)?

android - 如何以编程方式打开蓝牙设置 Activity ?