I am trying to implement a feature in an App that shows an alert when the internet connection is not available. The alert has two actions (OK and Settings), whenever a user clicks on settings, I want to take them to the phone settings programmatically.
I am using Swift and Xcode.
word of warning: the
prefs:root
orApp-Prefs:root
URL schemes are considered private API. Apple may reject you app if you use those, here is what you may get when submitting your app:As above @niravdesai said App-prefs. I found that
App-Prefs:
works for both iOS 9, 10 and 11. devices tested. where asprefs:
only works on iOS 9.Using
UIApplication.openSettingsURLString
Update for Swift 4.2
Swift 2.x
Using
UIApplicationOpenSettingsURLString
App-Prefs:root=Privacy&path=LOCATION
worked for me for getting to general location settings. Note: only works on a device.Swift 4
NOTE: The following method works for all the versions below iOS 11, for higher versions the app might get rejected since it's a private API
Sometimes we want to take a user to settings other than our app settings. The following method will help you achieve that:
First, configure the URL Schemes in your project. You will find it in Target -> Info -> URL Scheme. click on + button and type prefs in URL Schemes
Swift 3
Swift
Objective-c
and following are all the available URLs
Note: Network setting will not be opened in a simulator, but the link will work on a real device.
Using @vivek's hint I develop an utils class based on Swift 3, hope you appreciate!
This is very helpful since that API's will change for sure and you can refactor once and very fast!