iOS 10 App跳轉到許可權設定介面(iOS10之前就不各個記錄了)
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:^(BOOL success) {}];
}
複製程式碼
私有方法跳轉
######(1)跳轉的URL(系統差異可能有些跳轉不了)
系統設定: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
關於本機: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=General&path=Reset
應用通知:Prefs:root=NOTIFICATIONS_ID&path=應用的boundleId
複製程式碼
######(2)實現方案MobileCoreServices.framework裡的私有API
NSString * defaultWork = [self getDefaultWork];//defaultWorkspace
NSString * bluetoothMethod = [self getBluetoothMethod];//openSensitiveURL:withOptions:
NSURL*url=[NSURL URLWithString:@"Prefs:root=Bluetooth"];
Class LSApplicationWorkspace = NSClassFromString(@"LSApplicationWorkspace");
[[LSApplicationWorkspace performSelector:NSSelectorFromString(defaultWork)] performSelector:NSSelectorFromString(bluetoothMethod) withObject:url withObject:nil];
複製程式碼
-(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=TETHERING",wifi是@"Prefs:root=WIFI"。注意Prefs的P是大寫。這麼寫也有弊端,如果蘋果的未公開方法一旦修改。我們必須重新進行修改。