跳转系统设置、WIFI、蓝牙
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_TIME
FaceTime: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
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 1
- 18
- 19
- 20
- 21
…
我们在想要跳转的时候只要简单的几行代码
NSURL *url = [NSURL URLWithString:@"prefs:root=Bluetooth"];if ([[UIApplication sharedApplication]canOpenURL:url]) { [[UIApplication sharedApplication]openURL:url];}
- 1
- 2
- 3
- 4
但是万恶的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];
- 1
- 2
- 3
因为是私有的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]; }}
- 11
- 12
- 13
- 14
- 15
- 18
- 19
- 20
- 21
- 22
- 23
- 24
是不是完全看不懂?其实就是把那些字符串,那些类,那些方法都使用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=Wallpaper
Siri: App-Prefs:root=SIRI
隐私: App-Prefs:root=Privacy
定位: App-Prefs:root=LOCATION_SERVICES
Safari: 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...25
之前的prefs或者Prefs 替换成最新的 App-Prefs
当前iOS10全部支持!亲测!不是私有方法!不是私有方法!不是私有方法!
过审核不是问题!全部支持!
其他的不用说啦!炫耀去吧……
再补充一个跳转到应用设置
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication]canOpenURL:url]) {
[[UIApplication sharedApplication]openURL:url];
}