问题

在iOS10之前,跳转到系统设置界面的某个指定界面的方式如下:

//打开定位服务界面
NSURL*url=[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url];
};

但是在iOS10上,调用canOpenURL:打开系统设置界面时控制台会报如下错误,并且无法跳转:

-canOpenURL: failed for URL: "Prefs:root=Privacy&path=LOCATION" - error: "The operation couldn’t be completed. (OSStatus error -10814.)"

原因是iOS10只允许如下方式跳转到设置里自己app的界面,对跳转到其他界面做了限制:

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

解决方法

可以使用 MobileCoreServices.framework 里的私有API:

- (BOOL)openSensitiveURL:(id)arg1 withOptions:(id)arg2;

头文件参考: LSApplicationWorkspace.h

使用方法:

//注意首字母改成了大写,prefs->Prefs
NSURL*url=[NSURL URLWithString:@"Prefs:root=Privacy&path=LOCATION"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:@selector(defaultWorkspace)] performSelector:@selector(openSensitiveURL:withOptions:) withObject:url withObject:nil];

MobileCoreServices.framework 不是私有库,所以直接使用 performSelector: 即可调用私有API。

注意

  • iOS10的系统URLScheme改成了首字母大写,使用小写的方式会无法打开。
  • 使用私有API的app无法通过App Store审核。你也可以尝试把私有类名和selector字符串混淆一下,绕过审核。例如 这位仁兄 用ASCII混淆的方法:
- (UIView *)statusBarView {
UIView *statusBar = nil;
NSData *data = [NSData dataWithBytes:(unsigned char []){0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x42, 0x61, 0x72} length:9];
NSString *key = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
id object = [UIApplication sharedApplication];
if ([object respondsToSelector:NSSelectorFromString(key)]) {
statusBar = [object valueForKey:key];
}
return statusBar;
}

不过,还是不建议使用私有API,因为它是不可靠的。也许某天苹果就把它移除了。

以下是摘抄自GitHub上的一段可以通过Google私有文件

2down vote

+100

Point 1: LSApplicationWorkspace is private api, so if you use this and will upload your app to app store, it will get rejected.

Point 2: If you are having any in-house app and still want to use this in your app, then below is the way to use it.

  1. Add MobileCoreServices Framework in your bundle
  2. Create LSApplicationWorkspace.h file with the code exactly same as the code provided at here "https://github.com/nst/iOS-Runtime-Headers/blob/master/Frameworks/MobileCoreServices.framework/LSApplicationWorkspace.h".
  3. Now add this LSApplicationWorkspace.h file into your bundle
  4. Create bridging header for your swift app
  5. Add #import "LSApplicationWorkspace.h" in your bridging header
  6. Now add import MobileCoreServices in your current file and add your code let test = LSApplicationWorkspace.defaultWorkSpace(), it will work fine.

NOTE: For using any private header, you must have to include its .h file into your code. You can find any private headers by searching "runtime headers" in google. You will get all runtime headers. And to include that header in your swift code, you need to go via bridging-header.

iOS10 openURL方法跳转到设置界面的更多相关文章

  1. 通过 openURL 方法跳转至设置 - iOS

    iOS 10 以下系统版本可以通过 openURL 的方式跳转至指定的设置界面,code 如下: NSURL *url = [NSURL URLWithString:@"prefs:root ...

  2. iOSapp内跳转到设置界面

    从app内跳转到设置界面的代码如下: NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString]; if ([[UIAp ...

  3. android中 检查网络连接状态的变化,无网络时跳转到设置界面

    1:在AndroidManifest.xml中加一个声明 <receiver android:name="NetCheckReceiver">    <inten ...

  4. android检查网络连接状态的变化,无网络时跳转到设置界面

    在AndroidManifest.xml中加一个声明<receiver android:name="NetCheckReceiver"> <intent-filt ...

  5. iOS 权限判断 跳转对应设置界面

    相机权限 1.1 使用说明 在合适的地方导入#import <AVFoundation/AVFoundation.h> 使用AVAuthorizationStatus类获取当前权限状态 在 ...

  6. android判断当前网络状态及跳转到设置界面

    今天,想做这个跳转到网络设置界面, 刚开始用 intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS); 不料老是出现settings.Wirele ...

  7. Android 跳转权限设置界面的终极方案

    转载请标明出处,维权必究:https://www.cnblogs.com/tangZH/p/10338377.html 有时候APP需要获取某些权限,要让用户手动打开,那么问题来了,若是直接提醒用户出 ...

  8. iOS10跳转至设置页面

    在iOS10之前,跳转到系统设置界面的某个指定界面的方式如下: //打开定位服务界面 NSURL*url=[NSURL URLWithString:@"prefs:root=Privacy& ...

  9. iOS开发之如何跳到系统设置里的各种设置界面

    跳到更多设置界面 除了跳到WiFi设置界面,能不能跳到其他的设置界面呢?比如:定位服务.FaceTime.音乐等等.都是可以的,一起来看看如何实现的! 定位服务 定位服务有很多APP都有,如果用户关闭 ...

随机推荐

  1. 第五天、vim,重定向,用户和组管理

    第五天.vim,重定向,用户和组管理 vim vi:Visual editor,文本编辑器 行编辑器:sed 全屏编辑器:vim,vi,nano 其他编辑器gedit,gvim 定义别名让vi等于vi ...

  2. 2019CSP游记

    \(CSP2019\)游记 写在前面 考完,终于深刻地认识到省一似乎和我想象的真不是一个难度.也罢,不然为什么\(NOIP\)改了名还是这么有含金量. 考前一天和一群同学们嚷嚷着要去吃散伙饭,说没拿到 ...

  3. 查找文件或目录(find、locate、whereis、which、whatis)

    find命令:可以按文件名.文件的类型.用户等条件来递归查找文件或目录 find  [路径]  [匹配表达式] ,常用选项如下 -name filename  按文件名 -user username ...

  4. 从surfaceflinger历史变更谈截屏

    众所周知,有一个程序screencap可以截屏,这个程序十分简单,只是使用了surfaceflinger服务的截屏功能. 所以要了解截屏,看surfaceflinger服务的代码是不二首选.但是sur ...

  5. 在lldb调试中调用c++函数 - 如何使用QuartzCore里面的日志消息

    承接上一篇,上一篇讲到可以在lldb调试中调用QuartzCore.framework里的CA::Render::Object::show方法来是观察CA::Render模块内的类的信息,但是在lld ...

  6. 你必须知道的容器日志 (2) 开源日志管理方案 ELK

    本篇已加入<.NET Core on K8S学习实践系列文章索引>,可以点击查看更多容器化技术相关系列文章.上一篇<你必须知道的容器日志(1)>中介绍了Docker自带的log ...

  7. java 学习第三天小练习

    今天做的是一些流程控制题,if...else,for循环等. 1.给定一个成绩,如果成绩大于80,则输出“奖励”.判断完后不管条件成不成立都要输出“继续努力”. package lianXiTi; i ...

  8. 护网杯一道crypto

    import os def xor(a,b): assert len(a)==len(b) c="" for i in range(len(a)): c+=chr(ord(a[i] ...

  9. 结合开源软件kaptcha讲解登录验证码功能的实现

    一.验证码生成之配置使用kaptcha 使用google开源的验证码实现类库kaptcha,通过maven坐标引入 <dependency> <groupId>com.gith ...

  10. 【2018寒假集训Day 1】【位运算】生成字符串

    生成字符串(strs) [问题描述] 假设字符串只由字符“0”,“1”,“”组成,其中字符“”表示该字符可由 字符“0”或“1”替代. 现有一些字符串,根据这些字符串生成所有可生成的字符串.如: {1 ...