擦邊球方法 (iOS 10可用)開始
// 注意Prefs的P是大寫。
NSString * defaultWork = [self getDefaultWork];
NSString * bluetoothMethod = [self getBluetoothMethod];
NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];
利用ASCII值進行拼裝組合方法。這樣可繞過審核。
-(NSString *) getDefaultWork{
NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x64,0x65,0x66,0x61,0x75,0x6c,0x74,0x57,0x6f,0x72,0x6b,0x73,0x70,0x61,0x63,0x65} length:16];
NSString *method = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
return method;
}
-(NSString *) getBluetoothMethod{
NSData *dataOne = [NSData dataWithBytes:(unsigned char []){0x6f, 0x70, 0x65, 0x6e, 0x53, 0x65, 0x6e, 0x73, 0x69,0x74, 0x69,0x76,0x65,0x55,0x52,0x4c} length:16];
NSString *keyone = [[NSString alloc] initWithData:dataOne encoding:NSASCIIStringEncoding];
NSData *dataTwo = [NSData dataWithBytes:(unsigned char []){0x77,0x69,0x74,0x68,0x4f,0x70,0x74,0x69,0x6f,0x6e,0x73} length:11];
NSString *keytwo = [[NSString alloc] initWithData:dataTwo encoding:NSASCIIStringEncoding];
NSString *method = [NSString stringWithFormat:@"%@%@%@%@",keyone,@":",keytwo,@":"];
return method;
}
結束
設置跳轉有三種方式,每一種的使用場景都不同。 并且你在跳轉到系統中自己應用下面設置的時候,你的應用要提前至少申請了某一個權限,如通知,定位等。否則,會引起崩潰。
- 方式一:
prefs:root=某項服務
- 方式二:
prefs:root=bundleID
- 方式三:
UIApplicationOpenSettingsURLString
本篇針對iOS7、iOS8、iOS9、iOS10,來介紹其中區別
一、跳轉方法
iOS系統版本 < 10.0
NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
if( [[UIApplication sharedApplication]canOpenURL:url] ) {
[[UIApplication sharedApplication]openURL:url];
}
iOS系統版本 >= 10.0
if( [[UIApplication sharedApplication]canOpenURL:url] ) {
[[UIApplication sharedApplication]openURL:url options:@{}completionHandler:^(BOOL success) {
}];
}
二、跳轉到哪里去?(系統的設置,系統中自己應用下面的設置)
- 方式一:
iOS系統版本 <= iOS7 , 只能跳轉到 系統設置頁面
NSURL *url= [NSURL URLWithString:@"prefs:root=LOCATION_SERVICES"];
跳轉到: 隱私-定位服務。
prefs:root=某項服務
系統設置:prefs:root=INTERNET_TETHERING
WIFI設置:prefs:root=WIFI
藍牙設置:prefs:root=Bluetooth
系統通知:prefs:root=NOTIFICATIONS_ID
通用設置:prefs:root=General
顯示設置:prefs:root=DISPLAY&BRIGHTNESS
壁紙設置:prefs:root=Wallpaper
聲音設置:prefs:root=Sounds
隱私設置:prefs:root=privacy
蜂窩網路:prefs:root=MOBILE_DATA_SETTINGS_ID
音樂:prefs:root=MUSIC
APP Store:prefs:root=STORE
Notes:prefs:root=NOTES
Safari:prefs:root=Safari
Music:prefs:root=MUSIC
photo":prefs:root=Photos
- 方式二 :
iOS系統版本 >= iOS8 ,支持跳轉到第三方應用的設置界面中
使用prefs:root=bundleID ,bundleID是你第三方應用工程的唯一ID
局限性:只支持iOS8,iOS9系統,在iOS10系統上,不會跳轉。 在iOS7系統上,僅僅只是跳轉到設置應用,不推薦使用。
如果需要繼續向項目內層進行跳轉,可以通過添加path路徑的方式,如下:
關于本機:prefs:root=General&path=About
軟件升級:prefs:root=General&path=SOFTWARE_UPDATE_LINK
日期時間:prefs:root=General&path=DATE_AND_TIME
Accessibility:prefs:root=General&path=ACCESSIBILITY
鍵盤設置:prefs:root=General&path=Keyboard
VPN:prefs:root=General&path=VPN
壁紙設置:@"prefs:root=Wallpaper
聲音設置:prefs:root=Sounds
隱私設置:prefs:root=privacy
APP Store:prefs:root=STORE
還原設置:prefs:root=General&path=Reset
應用通知:prefs:root=NOTIFICATIONS_ID&path=應用的boundleId
- 方式三:
iOS系統版本 >= iOS10,支持跳轉到自己應用設置,不支持跳轉到系統設置
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
UIApplicationOpenSettingsURLString
字段,是在iOS8上才提供的,支持iOS8,iOS9,iOS10系統,推薦使用。
iOS系統版本>= iOS10,支持跳轉到自己應用設置,不支持跳轉到系統設置
只認
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
跳轉。
而 prefs:root=bundleID和 prefs:root=服務 都將不起作用。
總結一下:
- 方式一:
prefs:root=
某項服務 適用于 小于 iOS10的系統; - 方式二:
prefs:root=bundleID
適用于 大于等于iOS8系統,小于iOS10的系統 - 方式三:
UIApplicationOpenSettingsURLString
適用于 大于等于iOS8的系統
注意:小于iOS 10 想要實現應用內跳轉到系統設置界面功能,需要先在Targets-Info-URL Types-URL Schemes中添加prefs
-(void)btnSettingClick:(UIButton *)sender {
if ([[UIApplication sharedApplication] canOpenURL:[NSURL URLWithString:@"prefs:root=General&path=About"]]) {
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=About"]];
}
URLWithString屬性
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATIONS_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI