美文网首页iOS基本功
App跳转到权限设置界面

App跳转到权限设置界面

作者: 啊哈呵 | 来源:发表于2017-02-24 18:16 被阅读203次
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是大写。这么写也有弊端,如果苹果的未公开方法一旦修改。我们必须重新进行修改。

相关文章

网友评论

本文标题:App跳转到权限设置界面

本文链接:https://www.haomeiwen.com/subject/djiwwttx.html