iOS,iOS10 跳转系统设置、WIFI、蓝牙…

来源:互联网 发布:java decompiler使用 编辑:程序博客网 时间:2024/05/29 05:52

iOS10跳转系统设置、WIFI、蓝牙…

iOS自我们熟悉以来,就一直与Android有着不一样的体验,
系统更加流畅,使用更加舒适,
同时较高与Android的价格也导致了它的特殊性,
iOS系统的封闭和很多权限的限制导致了我们在开发的时候经常会遇到很多无法条件无法实现
就比如iOS10以前,我们开发的应用想要跳转到系统设置,跳转到蓝牙,跳转到WIFI…
iOS开发工程师们都很熟悉,系统给我们提供了一套URL,我们只要使用这一套就OK了
在iOS10以前,
可能会用到的这些

蜂窝网络:prefs:root=MOBILE_DATA_SETTINGS_IDWi-Fi:prefs:root=WIFI定位服务:prefs:root=LOCATION_SERVICES个人热点:prefs:root=INTERNET_TETHERING关于本机:prefs:root=General&path=About辅助功能:prefs:root=General&path=ACCESSIBILITY飞行模式:prefs:root=AIRPLANE_MODE锁定:prefs:root=General&path=AUTOLOCK亮度:prefs:root=Brightness蓝牙:prefs:root=Bluetooth时间设置:prefs:root=General&path=DATE_AND_TIMEFaceTime:prefs:root=FACETIME设置:prefs:root=General设置 prefs:root=SETTING定位服务 prefs:root=LOCATION_SERVICES键盘设置:prefs:root=General&path=KeyboardiCloud:prefs:root=CASTLEiCloud备份:prefs:root=CASTLE&path=STORAGE_AND_BACKUP语言:prefs:root=General&path=INTERNATIONAL定位:prefs:root=LOCATION_SERVICES音乐:prefs:root=MUSIC


我们在想要跳转的时候只要简单的几行代码

NSURL *url = [NSURL URLWithString:@"prefs:root=Bluetooth"];if ([[UIApplication sharedApplication]canOpenURL:url]) {   [[UIApplication sharedApplication]openURL:url];}

但是万恶的iOS10来了,就一切都变了
以上的全部都失效了,一切都没有用了
无论是prefs:root=Bluetooth 还是 Prefs:root=Bluetooth 都没有用
那么怎么跳转呢?
但是网上面又有说Prefs:root=Bluetooth 这种是可以的?
后来经测试这个只在Widge里有效,App中无效!

于是有大神想到了私有的API

NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");    [[LSApplicationWorkspace performSelector:@selector(defaultWorkspace)] performSelector:@selector(openSensitiveURL:withOptions:) withObject:url withObject:nil];

因为是私有的API,可能会过不了审核,于是又有了下面的变种
利用ASCII值进行拼装组合方法。这样可绕过审核。

SignedByte classOneByte[] = {0x4c,0x53,0x41,0x70,0x70,0x6c,0x69,0x63,0x61,0x74,0x69,0x6f,0x6e,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65};NSString *classOneString = [[NSString alloc] initWithData:[NSData dataWithBytes:classOneByte length:sizeof(classOneByte)] encoding:NSASCIIStringEncoding];Class classOne = NSClassFromString(classOneString);SignedByte selectOneByte[] = {0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65};NSString *selectOneString = [[NSString alloc] initWithData:[NSData dataWithBytes:selectOneByte length:sizeof(selectOneByte)] encoding:NSASCIIStringEncoding];SEL selectOne = NSSelectorFromString(selectOneString);if ([classOne respondsToSelector:selectOne]) { Class classTwo = [classOne performSelector:selectOne];SignedByte selectTwoByte[] = {0x6f,0x70,0x65,0x6e,0x53,0x65,0x6e,0x73,0x69,0x74,0x69,0x76,0x65,0x55,0x52,0x4c,0x3a,0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73,0x3a}; NSString *selectTwoString = [[NSString alloc] initWithData:[NSData dataWithBytes:selectTwoByte length:sizeof(selectTwoByte)] encoding:NSASCIIStringEncoding]; SEL selectTwo = NSSelectorFromString(selectTwoString);  SignedByte urlByte[] = {0x50,0x72,0x65,0x66,0x73,0x3a,0x72,0x6f,0x6f,0x74,0x3d,0x42,0x6c,0x75,0x65,0x74,0x6f,0x6f,0x74,0x68}; NSString *urlString = [[NSString alloc] initWithData:[NSData dataWithBytes:urlByte length:sizeof(urlByte)] encoding:NSASCIIStringEncoding];  NSURL *url = [NSURL URLWithString:urlString]; if ([classTwo respondsToSelector:selectTwo]) {      [classTwo performSelector:selectTwo withObject:url withObject:nil];  }}

是不是完全看不懂?其实就是把那些字符串,那些类,那些方法都使用ASCII进行了转换而已…

但是热更新事件来的很突然,审核系统开始对于respondsToSelector:和performSelector:有了一点关注,担心上面的方法会失效,毕竟是私有,不靠谱,
那么有没有靠谱的不是私有的?

答案是有!
千百次尝试,终于找到了!!

Wi-Fi: App-Prefs:root=WIFI蓝牙: App-Prefs:root=Bluetooth蜂窝移动网络: App-Prefs:root=MOBILE_DATA_SETTINGS_ID个人热点: App-Prefs:root=INTERNET_TETHERING运营商: App-Prefs:root=Carrier通知: App-Prefs:root=NOTIFICATIONS_ID通用: App-Prefs:root=General通用-关于本机: App-Prefs:root=General&path=About通用-键盘: App-Prefs:root=General&path=Keyboard通用-辅助功能: App-Prefs:root=General&path=ACCESSIBILITY通用-语言与地区: App-Prefs:root=General&path=INTERNATIONAL通用-还原: App-Prefs:root=Reset墙纸: App-Prefs:root=WallpaperSiri: App-Prefs:root=SIRI隐私: App-Prefs:root=Privacy定位: App-Prefs:root=LOCATION_SERVICESSafari: App-Prefs:root=SAFARI音乐: App-Prefs:root=MUSIC音乐-均衡器: App-Prefs:root=MUSIC&path=com.apple.Music:EQ照片与相机: App-Prefs:root=PhotosFaceTime: App-Prefs:root=FACETIME

之前的prefs或者Prefs 替换成最新的 App-Prefs

当前iOS10全部支持!亲测!不是私有方法!不是私有方法!不是私有方法!
过审核不是问题!全部支持!
其他的不用说啦!炫耀去吧……

再补充一个跳转到应用设置

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];if ([[UIApplication sharedApplication]canOpenURL:url]) {    [[UIApplication sharedApplication]openURL:url];}
原创粉丝点击