直播 IM程序员iOS

iOS一行代码带你跳转系统各设置页面

2017-03-23  本文已影响2465人  Qinz
Qinz
iOS开发中,有时会涉及到跳转到系统设置的界面,比如打开蓝牙,通知等,废话不多说,直接上图:Demo给出了31种界面的跳转,当然你也可以根据我下面第三步反映的规律进行其它页面的跳转~
1.gif 2.gif 3.gif 4.gif 5.gif
第一步:配置info信息,添加URL Sechmes的字段为prefs,不配置是没办法跳转的!
配置info
第二步:上代码 下面是本Demo所涉及所有跳转页面
  let listArr = ["无线局域网","蓝牙","个人热点","运营商","通知","睡眠","通用","调节亮度","墙纸",
"声音","siri语音助手","隐私","电话","icloud","iTunes Strore 与 APP Store","safari","关于本机",
"软件更新","辅助功能","日期与时间","键盘","存储空间","语言与地区","VPN","描述文件与设备管理","音乐",
"备忘录","照片与相机","还原","Twiter","Facebook"]
 //跳转系统设置页面
    func jump(url:String?){
        
        guard let jumpUrl = URL.init(string: url!) else {
            return
        }
        if UIApplication.shared.canOpenURL(jumpUrl)
        {
            if #available(iOS 10.0, *){
                UIApplication.shared.open(jumpUrl, options: [:], completionHandler: { (success) in
                    if success {
                        print("跳转成功")
                    }
                })
            }else{
                UIApplication.shared.openURL(jumpUrl)
            }
        }
    }
 
    //MARK: -- 选择每个cell执行的操作
    public func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        
        switch indexPath.row {
            
        case 0://无线局域网
            jump(url: "App-prefs:root=WIFI")
        case 1: //蓝牙
            jump(url: "App-Prefs:root=Bluetooth")
        case 2: //个人热点
            jump(url: "App-prefs:root=INTERNET_TETHERING")
        case 3: //运营商
            jump(url: "App-prefs:root=Carrier")
        case 4: //通知:需要大写后面加上ID
            jump(url: "App-prefs:root=NOTIFICATIONS_ID")
        case 5: //睡眠
            jump(url: "App-prefs:root=DO_NOT_DISTURB")
        case 6: //通用
            jump(url: "App-prefs:root=General")
        case 7: //调节亮度
            jump(url: "App-prefs:root=DISPLAY&BRIGHTNESS")
        case 8://墙纸
            jump(url: "App-prefs:root=Wallpaper")
        case 9://声音
            jump(url: "App-prefs:root=Sounds")
        case 10://siri语音助手
            jump(url: "App-prefs:root=SIRI")
        case 11://隐私
            jump(url: "App-prefs:root=Privacy")
        case 12: //电话
            jump(url: "App-prefs:root=Phone")
        case 13:  //icloud
            jump(url: "App-prefs:root=CASTLE")
        case 14://iTunes Strore 与 APP Store
            jump(url: "App-prefs:root=STORE")
        case 15://safari
            jump(url: "App-prefs:root=SAFARI")
        case 16: //关于本机
            jump(url: "App-prefs:root=General&path=About")
        case 17://软件更新
            jump(url: "App-prefs:root=General&path=SOFTWARE_UPDATE_LINK")
        case 18: //辅助功能
            jump(url: "App-prefs:root=General&path=ACCESSIBILITY")
        case 19: //日期与时间
            jump(url: "App-prefs:root=General&path=DATE_AND_TIME")
        case 20: //键盘
            jump(url: "App-prefs:root=General&path=Keyboard")
        case 21://存储空间
            jump(url: "App-prefs:root=CASTLE&path=STORAGE_AND_BACKUP")
        case 22: //语言与地区
            jump(url: "App-prefs:root=General&path=Language_AND_Region")
        case 23://VPN
            jump(url: "App-prefs:root=General&path=VPN")
        case 24://描述文件与设备管理
            jump(url: "App-prefs:root=General&path=ManagedConfigurationList")
        case 25://音乐
            jump(url: "App-prefs:root=MUSIC")
        case 26://备忘录
            jump(url: "App-prefs:root=NOTES")
        case 27: //照片与相机
            jump(url: "App-prefs:root=Photos")
        case 28://还原
            jump(url: "App-prefs:root=General&path=Reset")
        case 29: //Twiter
            jump(url: "App-prefs:root=TWITTER")
        case 30: //Facebook
            jump(url: "App-prefs:root=FACEBOOK")
            
        default:
            break
        }
    }
第三步:扩展
       
        case 0://无线局域网
            jump(url: "App-prefs:root=WIFI")
        case 1: //蓝牙
            jump(url: "App-Prefs:root=Bluetooth")
        case 2: //个人热点
            jump(url: "App-prefs:root=INTERNET_TETHERING")
        case 3: //运营商
            jump(url: "App-prefs:root=Carrier")
       case 4: //通知:需要大写后面加上ID
            jump(url: "App-prefs:root=NOTIFICATIONS_ID")
        case 5: //睡眠
            jump(url: "App-prefs:root=DO_NOT_DISTURB")
        case 6: //通用
            jump(url: "App-prefs:root=General")

1.png

总结: 基本都是 jump(url: "App-Prefs:root=Bluetooth") ,root等于号后面的就是该英文单词,当然有的是用长的英文单词是用“_”来连接,如jump(url: "App-prefs:root=NOTIFICATIONS_ID"),有的是将小写改为大写,如SAFARI。可以自己去试试就明白其中的关联了~是不是很简单呢?根据该规律还有些界面自己设置也可以跳转过去,当然有些也是跳不过去的!

OC也是一行代码调用:
 [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"App-Prefs:root=Bluetooth"]];

最后附上demo下载地址:https://git.oschina.net/Qinz_323/JumpDemo

参考来源:http://stackoverflow.com/questions/9092142/ios-uialertview-button-to-go-to-setting-app

我是Qinz,希望我的文章对你有帮助。

上一篇下一篇

猜你喜欢

热点阅读