iOS应用内部开启地图设置

配置首次应用打开请求用户授权

  1. 导入框架MapKit.framework
  2. 进行授权,在info.plist中配置key。这里有两种授权:
    1)NSLocationAlwaysUsageDescription 用户同意后可永久使用
    2)NSLocationWhenInUsageDescription 在用户打开应用期间使用。
    上面这两种文案在隐私->定位服务->App名字->始终,使用应用期间通过应用说明查看。

应用使用期间,用户关闭了系统定位,引导用户开启系统定位

  if (![CLLocationManager locationServicesEnabled]) {
        NSLog(@"系统定位未开启");
        UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"未开启" message:@"未开启定位" preferredStyle:UIAlertControllerStyleAlert];
        [alertController addAction:[UIAlertAction actionWithTitle:@"去开启" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
            NSURL *url = [NSURL URLWithString:@"App-Prefs:root=Privacy&path=LOCATION"];
            if ([[UIApplication sharedApplication] canOpenURL:url]) {
                [[UIApplication sharedApplication] openURL:url];
            }
        }]];
        [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            //
        }]];
        [self presentViewController:alertController animated:YES completion:nil];
    }else {
        NSLog(@"系统定位开启");
    }

这时跳转的界面为:通用-隐私-定位服务

使用应用期间,用户关闭了该程序的定位服务(设置为永不)

 if ([CLLocationManager authorizationStatus] != kCLAuthorizationStatusAuthorizedAlways) {
            NSLog(@"未授权app定位");
            UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"未授权" message:@"未授权应用定位" preferredStyle:UIAlertControllerStyleAlert];
            [alertController addAction:[UIAlertAction actionWithTitle:@"去授权" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) {
                NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
                if ([[UIApplication sharedApplication] canOpenURL:url]) {
                    [[UIApplication sharedApplication] openURL:url];
                }
            }]];
            [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
                //
            }]];
            [self presentViewController:alertController animated:YES completion:nil];

        }

点击确定,跳转到隐私->定位服务->App名字在这里设置选择应用使用期间或始终。
下图为关闭应用定位功能后跳转

iOS应用内部开启地图设置_第1张图片
未开启定位跳转

下图为为开启系统定位后跳转
iOS应用内部开启地图设置_第2张图片
关闭应用定位功能跳转

最后附上跳转系统相关应用的schema

电池电量 Prefs:root=BATTERY_USAGE
通用设置Prefs:root=General
存储空间Prefs:root=General&path=STORAGE_ICLOUD_USAGE/DEVICE_STORAGE蜂窝数据Prefs:root=MOBILE_DATA_SETTINGS_IDWi-Fi
设置Prefs:root=WIFI
蓝牙设置 Prefs:root=Bluetooth
定位设置Prefs:root=Privacy&path=LOCATION
辅助功能Prefs:root=General&path=ACCESSIBILITY
关于手机Prefs:root=General&path=About
键盘设置Prefs:root=General&path=Keyboard
显示设置 Prefs:root=DISPLAY
声音设置Prefs:root=SoundsApp Store
设置 Prefs:root=STORE
墙纸设置Prefs:root=Wallpaper
打开电话 Mobilephone://
世界时钟Clock-worldclock:
闹钟Clock-alarm://
秒表Clock-stopwatch://
倒计时Clock-timer://
打开相册Photos://

你可能感兴趣的:(iOS应用内部开启地图设置)