How to open settings app programmatically?

▼魔方 西西 提交于 2019-11-30 11:22:43

Try this.

if let appSettings = URL(string: UIApplicationOpenSettingsURLString) {
    UIApplication.shared.open(appSettings, options: [:], completionHandler: nil)
}

Xcode 8.2.1 - iOS 10

Update on 11-Oct-2016:

It won't work in iOS10 anymore. So far I haven't found any workaround. If you guys have any solution please let me know. thanks.

======================================

if the iOS version <= iOS9, you need set URL types:

You can do in this way:

    let url:NSURL! = NSURL(string : "prefs:root=")
    UIApplication.sharedApplication().openURL(url)

I have a demo on github: http://github.com/zhihuitang/SettingDemo.git

And you can find all available URLs as follows: http://iphonedevwiki.net/index.php/Preferences.app Preferences app registers a private URL scheme, prefs:, the list below details opening specific views 1[2]

prefs:root=General&path=About
prefs:root=General&path=ACCESSIBILITY
prefs:root=AIRPLANE_MODE
prefs:root=General&path=AUTOLOCK
prefs:root=General&path=USAGE/CELLULAR_USAGE
prefs:root=General&path=Bluetooth
prefs:root=General&path=DATE_AND_TIME
prefs:root=FACETIME
prefs:root=General
prefs:root=General&path=Keyboard
prefs:root=CASTLE
prefs:root=CASTLE&path=STORAGE_AND_BACKUP
prefs:root=General&path=INTERNATIONAL
prefs:root=LOCATION_SERVICES
prefs:root=ACCOUNT_SETTINGS
prefs:root=MUSIC
prefs:root=MUSIC&path=EQ
prefs:root=MUSIC&path=VolumeLimit
prefs:root=General&path=Network
prefs:root=NIKE_PLUS_IPOD
prefs:root=NOTES
prefs:root=NOTIFICATIONS_ID
prefs:root=Phone
prefs:root=Photos
prefs:root=General&path=ManagedConfigurationList
prefs:root=General&path=Reset
prefs:root=Sounds&path=Ringtone
prefs:root=Safari
prefs:root=General&path=Assistant
prefs:root=Sounds
prefs:root=General&path=SOFTWARE_UPDATE_LINK
prefs:root=STORE
prefs:root=TWITTER
prefs:root=General&path=USAGE
prefs:root=VIDEO
prefs:root=General&path=Network/VPN
prefs:root=Wallpaper
prefs:root=WIFI
prefs:root=INTERNET_TETHERING

hope this helpful to you.

Boosa Ramesh

YES, They made changes in iOS 10, Please change "prefs:" to "App-Prefs:"

guard let profileUrl = URL(string:"App-Prefs:root=General&path=ManagedConfigurationList") else {
    return
}

if UIApplication.shared.canOpenURL(profileUrl) {
    UIApplication.shared.open(profileUrl, completionHandler: { (success) in
        print(" Profile Settings opened: \(success)")
    })
}

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!