How to open settings app programmatically?
Asked Answered
S

4

26

I'm using swift with ios 8.3. I want to open settings app from my application. I know that using the code

UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)

will open my app settings. But I don't want to open my app settings. I just want to open the settings app and stay in the main page. If possible, navigate to "Cellular". Is there any way to acheive this?

Sensate answered 4/7, 2015 at 4:23 Comment(2)
hello, have you found any solution for open setting main page ?Quirites
No. I think there's no solution for my questionSensate
M
42

Try this.

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

Xcode 11.5 - iOS > 10

Marten answered 6/1, 2017 at 19:19 Comment(4)
This should be marked as the correct answer; others use iOS internals that can result in App Store rejections.Fredericfrederica
this is opening my app settings on iOS 12Borchert
There is no way currently to open even the main Settings screen (using public API), only settings of your app in Settings.Zemstvo
perfect. This is the answer.Candlepower
G
19

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: enter image description here

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.

Gypsum answered 27/10, 2015 at 15:19 Comment(9)
That code is what I am using now. Sachin Rocken, could you paste your code here? Let's see what is the problem.Rein
let url:NSURL! = NSURL(string : "prefs:root=General") UIApplication.sharedApplication().openURL(url) That doesn't work.Fatality
@User9527 , I tried your code. In viewdidload I used let url:NSURL! = NSURL(string : "prefs:root=") UIApplication.sharedApplication().openURL(url) and it's not working. I don't know how it's working for you. Could you please give a sample project using any sharing services available.Sensate
@Sachin Rocken, I made a demo in github, please check if it works with you:github.com/zhihuitang/SettingDemo.gitRein
It is actually working if you consider this tip here to "configure the URL Schemes in your project": gist.github.com/phynet/471089a51b8f940f0fb4Foreordination
Have anybody got the solution for iOS 10?Lobbyist
Under iOS 10 "prefs:###" has been changed to "App-Prefs:###". The rest of the string should be the same.Annulet
Please use my code which i have given above. Its successfully working mineMotel
This API is private and Apple will most likely reject your app if you will want to send it to the store.Zemstvo
M
10

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)")
    })
}

Motel answered 13/2, 2017 at 9:42 Comment(3)
This is a hack and will result in rejection from App Store.Handy
hoo really, Thanks for your information Sibir, Is there any alternative for this?Motel
@BoosaRamesh Doesn't look like it. :(Silda
C
3

Xcode 14: you can do:

// System settings:
let url = URL(string: UIApplication.openSettingsURLString)!
UIApplication.shared.open(url)

// Notifications settings:
URL(string: UIApplication.openNotificationSettingsURLString)!
UIApplication.shared.open(url)
Cnidus answered 23/3, 2023 at 12:43 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.