iOS进阶iOS之功能细节iOS开发经验与技巧

iOS 10 调用系统"设置"里的功能(全)

2017-03-14  本文已影响398人  1b3bd36d9d21

擦边球方法 (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;
}

结束

设置跳转有三种方式,每一种的使用场景都不同。 并且你在跳转到系统中自己应用下面设置的时候,你的应用要提前至少申请了某一个权限,如通知,定位等。否则,会引起崩溃。

一、跳转方法

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) {
    }];
}

二、跳转到哪里去?(系统的设置,系统中自己应用下面的设置)

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
关于本机: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
NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

跳转。
而 prefs:root=bundleID和 prefs:root=服务 都将不起作用。

总结一下:

注意:小于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
上一篇 下一篇

猜你喜欢

热点阅读