问题

在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. UiPath之DataTable转换为List和Array

    今天给大家分享一下,如何将DataTable转为List和Array,为此小U也花了不少时间研究,最后发现没有那么复杂. 先来说说List和Array的区别: List:就像一个链条,存储数据的空间可 ...

  2. Phone Code

    Polycarpus has n friends in Tarasov city. Polycarpus knows phone numbers of all his friends: they ar ...

  3. 必知必会的JavaJDK工具

    JDK中有很多用于监控诊断的系统工具,对于Java程序员来说,无疑是用来了解自己程序运行时性能好坏的强大工具. 在JDK的bin目录下就可以找到这些工具. JPS 在Linux有一个命令叫做ps,可以 ...

  4. C++中对C的扩展学习新增语法——强枚举

    枚举类型 C++中对枚举的加强: 1.C++不允许非枚举值赋值给枚举类型,不允许其他枚举类型的值赋值给当前枚举类型,而C语言中是允许的. 2.枚举值具有外层作用域,容易造成名字冲突. 3.不同类型的枚 ...

  5. nginx+uWSGI+django+virtualenv+superviso发布web服务器

    1.环境依赖 yum groupinstall "Development tools" -y yum install zlib-devel bzip2-devel pcre-dev ...

  6. OFFICE 2010 每次打开提示安装的问题

    OFFICE2010 安装后每次打开 文件总是提示配置 解决办法: 前提是office已经激活 注册表找到 HKEY_CURRENT_USER\Software\Microsoft\Office\14 ...

  7. 力扣(LeetCode)二进制求和 个人题解

    给定两个二进制字符串,返回他们的和(用二进制表示). 输入为非空字符串且只包含数字 1 和 0. 示例 1: 输入: a = "11", b = "1" 输出: ...

  8. python获取随机验证码或者下发激活码

    http://stackoverflow.com/questions/2823316/generate-a-random-letter-in-python >>> import ra ...

  9. ZeroC ICE的远程调用框架 Slice如何帮助我们进行Ice异步编程(AMI,AMD)

    Slice最大的用处就是为我们使用Ice进行编程,代劳绝大部分的重复性代码,并提供一些帮助性的框架代码,如用于AMI和AMD方式进行异步编程的回调框架. 当Slice不为我们生成代码时,我们仍然可以按 ...

  10. tomcat-9.0.20部署后输出窗口乱码解决方案

    问题:启动tomcat的时候,窗口乱码,默认都是UTF-8的,但是控制台是GBK的,要保持一致 可以通过控制台查看本机的编码: : 936  代表  GB2312 解决办法:打开tomcat目录下的c ...