问题

在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. Redis 的底层数据结构(压缩列表)

    上一篇我们介绍了 redis 中的整数集合这种数据结构的实现,也谈到了,引入这种数据结构的一个很大的原因就是,在某些仅有少量整数元素的集合场景,通过整数集合既可以达到字典的效率,也能使用远少于字典的内 ...

  2. php递归删除文件夹

    php递归删除文件夹 <pre> public function deldir($path) { //如果是目录则继续 if (is_dir($path)) { //扫描一个文件夹内的所有 ...

  3. .NET Core 3.0 单元测试与 Asp.Net Core 3.0 集成测试

    单元测试与集成测试 测试必要性说明 相信大家在看到单元测试与集成测试这个标题时,会有很多感慨,我们无数次的在实践中提到要做单元测试.集成测试,但是大多数项目都没有做或者仅建了项目文件.这里有客观原因, ...

  4. mysql里面的时间获取(格式年月日)

    1.当前日期 select DATE_SUB(curdate(),INTERVAL 0 DAY) ; 2.明天日期 select DATE_SUB(curdate(),INTERVAL -1 DAY) ...

  5. 关于MXNet

    关于人工智能,机器学习,深度学习 三者关系:从宏观到微观. 机器学习是人工智能的一部分,深度学习是机器学习的一部分. 基础:大数据. 关于深度学习 深度学习基于神经网络, 关于神经网络:通过叠加网络层 ...

  6. ZeroC ICE中的对象模型和概念

    Ice对象的模型和概念. Ice Object并非是我们的接口实现类的实例对象.我们的接口实现类的实例对象只是充当Ice Object的Servant的角色.一个Ice Object可以有众多Serv ...

  7. SQL中Truncate的用法

    SQL中Truncate的用法转自:http://www.studyofnet.com/news/555.html本文导读:删除表中的数据的方法有delete,truncate, 其中TRUNCATE ...

  8. Blocked a frame with origin XXX from accessing a cross-origin 。iframe跨域问题

    在前端开发的过程中,我们常常会用到iframe去在我们的页面中引用一个子页面,而父子页面又常常会有交互.在同域情况下,子页面如果想要访问父页面中的window对象中的方法的话,直接在当前页面中使用wi ...

  9. Unittest框架的从零到壹(一)

    前言 Python中有非常多的单元测试框架,如unittest.pytest.nose.doctest等,Python2.1及其以后的版本已经将unittest作为一个标准模块放入Python开发包中 ...

  10. 理解Redis持久化

    本文首发于:https://mp.weixin.qq.com/s/WVUGWuNrGoyY_7aDf7NNmA 微信公众号:后端技术指南针 0.前言 通俗讲持久化就是将内存中的数据写入非易失介质中,比 ...