225

Okay, I know that there are many question about it, but they are all from many time ago.

So. I know that it is possible because the Map app does it.

In the Map app if I turn off the localization for this app, it send me a message, and if I press okay, the "Settings App" will be open. And my question is, how is this possible? How can I open the "Setting app" from my own app?

Basically I need to do the same thing, if the user turn off the location for my app, then I'll show him a message saying something that will open the "Setting app"

CopsOnRoad
  • 237,138
  • 77
  • 654
  • 440
FelipeDev.-
  • 3,113
  • 3
  • 22
  • 32
  • Check this one http://stackoverflow.com/questions/377102/how-do-i-open-the-settings-application-from-my-application/24570751#24570751 – Yatheesha Jul 04 '14 at 09:19
  • 1
    You can open settings app programmatically in iOS8(but not in lower versions of iOS).code below in answers. – Karan Dua Aug 04 '14 at 08:02

19 Answers19

357

As mentioned by Karan Dua this is now possible in iOS8 using UIApplicationOpenSettingsURLString see Apple's Documentation.

Example:

Swift 4.2

UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!)

In Swift 3:

UIApplication.shared.open(URL(string:UIApplicationOpenSettingsURLString)!)

In Swift 2:

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

In Objective-C

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

Prior to iOS 8:

You can not. As you said this has been covered many times and that pop up asking you to turn on location services is supplied by Apple and not by the App itself. That is why it is able to the open the settings application.

Here are a few related questions & articles:

is it possible to open Settings App using openURL?

Programmatically opening the settings app (iPhone)

How can I open the Settings app when the user presses a button?

iPhone: Opening Application Preferences Panel From App

Open UIPickerView by clicking on an entry in the app's preferences - How to?

Open the Settings app?

iOS: You’re Doing Settings Wrong

karlbsm
  • 347
  • 4
  • 9
Joe
  • 56,979
  • 9
  • 128
  • 135
  • If you need a more authoritative answer, you might try asking on the Apple Developer forums or filing a bug at — if it's a known issue it should come back as "behaves correctly" or a duplicate of the original bug. – Vincent Gable Aug 15 '11 at 20:40
  • 7
    [Not possible is rarely true in the field of programming.](http://stackoverflow.com/questions/14587370/how-some-apps-can-open-setting-app-programmatically-within-their-app#14587480) –  Mar 29 '13 at 06:52
  • I agree if you are willing to bend/break the rules. – Joe Mar 29 '13 at 11:36
  • 2
    This is now possible in iOS 8 using [NSURL URLWithString:UIApplicationOpenSettingsURLString] – LightningStryk Oct 27 '14 at 14:44
  • @Joe This solution is not working for iOS 10 . I am working on Xcode 8, swift 3. Any alternate solution please? – Khadija Daruwala Sep 23 '16 at 04:31
  • @joe i have worked in iOS 10. its not Works. if any other solution please update your answer. – sohil Oct 19 '16 at 05:55
  • I think, they still work with Extensions. Ex app is `Magic Launcher` in Appstore. – Trident Oct 21 '16 at 18:08
  • 1
    in swift 3 - UIApplication.shared.openURL(URL(string:UIApplicationOpenSettingsURLString)!) – Hanushka Suren Nov 04 '16 at 15:06
  • 1
    Be wary of using this method. I used it and a few months later my app got rejected with the following message from Apple: Your app uses the "prefs:root=" non-public URL scheme, which is a private entity. The use of non-public APIs is not permitted on the App Store because it can lead to a poor user experience should these APIs change. Continuing to use or conceal non-public APIs in future submissions of this app may result in the termination of your Apple Developer account, as well as removal of all associated apps from the App Store. – Nick Kirsten Aug 31 '18 at 09:08
  • @Nick Kirsten did you mean this answer or the answer bellow ?, I can't see any "prefs:root" phrase in the current answer. Also, what did you do instead ? – ChesterK2 Oct 01 '20 at 12:51
  • `openSettingsURLString` is a public API, see documentation: https://developer.apple.com/documentation/uikit/uiapplication/1623042-opensettingsurlstring – multitudes Jun 30 '21 at 15:02
134

From @Yatheeshaless's answer:

You can open settings app programmatically in iOS8, but not in earlier versions of iOS.

Swift:

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

Swift 4:

if let url = NSURL(string: UIApplicationOpenSettingsURLString) as URL? {
    UIApplication.shared.openURL(url)
}

Swift 4.2 (BETA):

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

Objective-C:

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Karan Dua
  • 2,401
  • 3
  • 15
  • 17
  • 27
    This appears to open your app's section of the Settings app. Users will have to hit Back a few times to see the main screen of Settings. – wjl Sep 25 '14 at 18:41
  • 1
    Small correction.. `[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];` – Paito Oct 08 '14 at 13:32
  • 12
    @Paito The above line is directing to **app private settings**. Is there any way to direct to **privacy** section of the device settings? Please comment if you know. This redirection is possible, as I found it in maps app where it directs to location settings in privacy section. – Pavan Kotesh Oct 10 '14 at 15:06
  • Not sure if it's possible, Apple apps often do things that we can't by using private APIs, the Google Maps app just goes to the App Settings not Location Services. – Paito Oct 15 '14 at 14:35
  • 1
    Small Swift correction: UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!) – vbezhenar Nov 11 '14 at 13:57
  • 1
    @PavanKotesh- Yes but the app settings will have what you need permission for, in my case i needed access to contacts, which do appear in app settings with above code. – Tejas K Feb 02 '16 at 10:40
60

YES!! you can launch Device Settings screen, I have tested on iOS 9.2

Step 1. we need to add URL schemes

Go to Project settings --> Info --> URL Types --> Add New URL Schemes

enter image description here

Step 2. Launch Settings programmatically Thanks to @davidcann

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];

Also we can launch sub-screens like Music, Location etc. as well by just using proper name

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=MUSIC"]];

See this full name list here shared by Henri Normak


Update:

As per the comment everyone wants to know what happens after this change to my application submission status?

So YES!! I got successful update submission and application is available on store without any complain.

Just to confirm, I Just downloaded this morning and disabled Location services, and then started the app, which asked me for location permission and then my alert popup was there to send me on settings -> location services page --> Enabled --> That's it!!

![NOTICE: Your app might be rejected ... even if it's approved it can be rejected in future version if you use this method...]4

Mihir Mehta
  • 13,743
  • 3
  • 64
  • 88
swiftBoy
  • 35,607
  • 26
  • 136
  • 135
38

Seems like you can use the prefs:<area> URL to open the settings and go to specific areas. Apple could change these and break your app so always check if you can open them first.

From this article they have listed some of them for iOS 13.1:

Settings URLs

iCloud

  • iCloud: prefs:root=CASTLE
  • iCloud Backup: prefs:root=CASTLE&path=BACKUP

Wireless Radios

  • Wi-Fi: prefs:root=WIFI
  • Bluetooth: prefs:root=Bluetooth
  • Cellular: prefs:root=MOBILE_DATA_SETTINGS_ID

Personal Hotspot

  • Personal Hotspot: prefs:root=INTERNET_TETHERING
  • Personal Hotspot ⇾ Family Sharing: prefs:root=INTERNET_TETHERING&path=Family%20Sharing
  • Personal Hotspot ⇾ Wi-Fi Password: prefs:root=INTERNET_TETHERING&path=Wi-Fi%20Password

VPN

  • VPN: prefs:root=General&path=VPN

Notifications

  • Notifications: prefs:root=NOTIFICATIONS_ID
  • Notifications ⇾ Siri Suggestions: prefs:root=NOTIFICATIONS_ID&path=Siri%20Suggestions

Sounds

  • Sounds: prefs:root=Sounds
  • Ringtone: prefs:root=Sounds&path=Ringtone

Do Not Disturb

  • Do Not Disturb: prefs:root=DO_NOT_DISTURB
  • Do Not Disturb ⇾ Allow Calls From: prefs:root=DO_NOT_DISTURB&path=Allow%20Calls%20From

Screen Time

  • Screen Time: prefs:root=SCREEN_TIME
  • Screen Time ⇾ Downtime: prefs:root=SCREEN_TIME&path=DOWNTIME
  • Screen Time ⇾ App Limits: prefs:root=SCREEN_TIME&path=APP_LIMITS
  • Screen Time ⇾ Always Allowed: prefs:root=SCREEN_TIME&path=ALWAYS_ALLOWED

General

  • General: prefs:root=General
  • General ⇾ About: prefs:root=General&path=About
  • General ⇾ Software Update: prefs:root=General&path=SOFTWARE_UPDATE_LINK
  • General ⇾ CarPlay: prefs:root=General&path=CARPLAY
  • General ⇾ Background App Refresh: prefs:root=General&path=AUTO_CONTENT_DOWNLOAD
  • General ⇾ Multitasking (iPad-only): prefs:root=General&path=MULTITASKING
  • General ⇾ Date & Time: prefs:root=General&path=DATE_AND_TIME
  • General ⇾ Keyboard: prefs:root=General&path=Keyboard
  • General ⇾ Keyboard ⇾ Keyboards: prefs:root=General&path=Keyboard/KEYBOARDS
  • General ⇾ Keyboard ⇾ Hardware Keyboard: prefs:root=General&path=Keyboard/Hardware%20Keyboard
  • General ⇾ Keyboard ⇾ Text Replacement: prefs:root=General&path=Keyboard/USER_DICTIONARY
  • General ⇾ Keyboard ⇾ One Handed Keyboard: prefs:root=General&path=Keyboard/ReachableKeyboard
  • General ⇾ Language & Region: prefs:root=General&path=INTERNATIONAL
  • General ⇾ Dictionary: prefs:root=General&path=DICTIONARY
  • General ⇾ Profiles: prefs:root=General&path=ManagedConfigurationList
  • General ⇾ Reset: prefs:root=General&path=Reset

Control Center

  • Control Center: prefs:root=ControlCenter
  • Control Center ⇾ Customize Controls: prefs:root=ControlCenter&path=CUSTOMIZE_CONTROLS

Display

  • Display: prefs:root=DISPLAY
  • Display ⇾ Auto Lock: prefs:root=DISPLAY&path=AUTOLOCK
  • Display ⇾ Text Size: prefs:root=DISPLAY&path=TEXT_SIZE

Accessibility

  • Accessibility: prefs:root=ACCESSIBILITY

Wallpaper

  • Wallpaper: prefs:root=Wallpaper

Siri

  • Siri: prefs:root=SIRI

Apple Pencil

  • Apple Pencil (iPad-only): prefs:root=Pencil

Face ID

  • Face ID: prefs:root=PASSCODE

Emergency SOS

  • Emergency SOS: prefs:root=EMERGENCY_SOS

Battery

  • Battery: prefs:root=BATTERY_USAGE
  • Battery ⇾ Battery Health (iPhone-only): prefs:root=BATTERY_USAGE&path=BATTERY_HEALTH

Privacy

  • Privacy: prefs:root=Privacy
  • Privacy ⇾ Location Services: prefs:root=Privacy&path=LOCATION
  • Privacy ⇾ Contacts: prefs:root=Privacy&path=CONTACTS
  • Privacy ⇾ Calendars: prefs:root=Privacy&path=CALENDARS
  • Privacy ⇾ Reminders: prefs:root=Privacy&path=REMINDERS
  • Privacy ⇾ Photos: prefs:root=Privacy&path=PHOTOS
  • Privacy ⇾ Microphone: prefs:root=Privacy&path=MICROPHONE
  • Privacy ⇾ Speech Recognition: prefs:root=Privacy&path=SPEECH_RECOGNITION
  • Privacy ⇾ Camera: prefs:root=Privacy&path=CAMERA
  • Privacy ⇾ Motion: prefs:root=Privacy&path=MOTION\

App Store

  • App Store: prefs:root=STORE
  • App Store ⇾ App Downloads: prefs:root=STORE&path=App%20Downloads
  • App Store ⇾ Video Autoplay: prefs:root=STORE&path=Video%20Autoplay

Wallet

  • Wallet: prefs:root=PASSBOOK

Passwords & Accounts

  • Passwords & Accounts: prefs:root=ACCOUNTS_AND_PASSWORDS
  • Passwords & Accounts ⇾ Fetch New Data: prefs:root=ACCOUNTS_AND_PASSWORDS&path=FETCH_NEW_DATA
  • Passwords & Accounts ⇾ Add Account: prefs:root=ACCOUNTS_AND_PASSWORDS&path=ADD_ACCOUNT

Mail

  • Mail: prefs:root=MAIL
  • Mail ⇾ Preview: prefs:root=MAIL&path=Preview
  • Mail ⇾ Swipe Options: prefs:root=MAIL&path=Swipe%20Options
  • Mail ⇾ Notifications: prefs:root=MAIL&path=NOTIFICATIONS
  • Mail ⇾ Blocked: prefs:root=MAIL&path=Blocked
  • Mail ⇾ Muted Thread Action: prefs:root=MAIL&path=Muted%20Thread%20Action
  • Mail ⇾ Blocked Sender Options: prefs:root=MAIL&path=Blocked%20Sender%20Options
  • Mail ⇾ Mark Addresses: prefs:root=MAIL&path=Mark%20Addresses
  • Mail ⇾ Increase Quote Level: prefs:root=MAIL&path=Increase%20Quote%20Level
  • Mail ⇾ Include Attachments with Replies: prefs:root=MAIL&path=Include%20Attachments%20with%20Replies
  • Mail ⇾ Signature: prefs:root=MAIL&path=Signature
  • Mail ⇾ Default Account: prefs:root=MAIL&path=Default%20Account

Contacts

  • Contacts: prefs:root=CONTACTS

Calendar

  • Calendar: prefs:root=CALENDAR
  • Calendar ⇾ Alternate Calendars: prefs:root=CALENDAR&path=Alternate%20Calendars
  • Calendar ⇾ Sync: prefs:root=CALENDAR&path=Sync
  • Calendar ⇾ Default Alert Times: prefs:root=CALENDAR&path=Default%20Alert%20Times
  • Calendar ⇾ Default Calendar: prefs:root=CALENDAR&path=Default%20Calendar

Notes

  • Notes: prefs:root=NOTES
  • Notes ⇾ Default Account: prefs:root=NOTES&path=Default%20Account
  • Notes ⇾ Password: prefs:root=NOTES&path=Password
  • Notes ⇾ Sort Notes By: prefs:root=NOTES&path=Sort%20Notes%20By
  • Notes ⇾ New Notes Start With: prefs:root=NOTES&path=New%20Notes%20Start%20With
  • Notes ⇾ Sort Checked Items: prefs:root=NOTES&path=Sort%20Checked%20Items
  • Notes ⇾ Lines & Grids: prefs:root=NOTES&path=Lines%20%26%20Grids
  • Notes ⇾ Access Notes from Lock Screen: prefs:root=NOTES&path=Access%20Notes%20from%20Lock%20Screen

Reminders

  • Reminders: prefs:root=REMINDERS
  • Reminders ⇾ Default List: prefs:root=REMINDERS&path=DEFAULT_LIST

Voice Memos

  • Voice Memos: prefs:root=VOICE_MEMOS

Phone

  • Phone: prefs:root=Phone

Messages

  • Messages: prefs:root=MESSAGES

FaceTime

  • FaceTime: prefs:root=FACETIME

Maps

  • Maps: prefs:root=MAPS
  • Maps ⇾ Driving & Navigation: prefs:root=MAPS&path=Driving%20%26%20Navigation
  • Maps ⇾ Transit: prefs:root=MAPS&path=Transit

Compass

  • Compass: prefs:root=COMPASS

Measure

  • Measure: prefs:root=MEASURE

Safari

  • Safari: prefs:root=SAFARI
  • Safari ⇾ Content Blockers: prefs:root=SAFARI&path=Content%20Blockers
  • Safari ⇾ Downloads: prefs:root=SAFARI&path=DOWNLOADS
  • Safari ⇾ Close Tabs: prefs:root=SAFARI&path=Close%20Tabs
  • Safari ⇾ Clear History and Data: prefs:root=SAFARI&path=CLEAR_HISTORY_AND_DATA
  • Safari ⇾ Page Zoom: prefs:root=SAFARI&path=Page%20Zoom
  • Safari ⇾ Request Desktop Website: prefs:root=SAFARI&path=Request%20Desktop%20Website
  • Safari ⇾ Reader: prefs:root=SAFARI&path=Reader
  • Safari ⇾ Camera: prefs:root=SAFARI&path=Camera
  • Safari ⇾ Microphone: prefs:root=SAFARI&path=Microphone
  • Safari ⇾ Location: prefs:root=SAFARI&path=Location
  • Safari ⇾ Advanced: prefs:root=SAFARI&path=ADVANCED

News

  • News: prefs:root=NEWS

Health

  • Health: prefs:root=HEALTH

Shortcuts

  • Shortcuts: prefs:root=SHORTCUTS

Music

  • Music: prefs:root=MUSIC
  • Music ⇾ Cellular Data: prefs:root=MUSIC&path=com.apple.Music:CellularData
  • Music ⇾ Optimize Storage: prefs:root=MUSIC&path=com.apple.Music:OptimizeStorage
  • Music ⇾ EQ: prefs:root=MUSIC&path=com.apple.Music:EQ
  • Music ⇾ Volume Limit: prefs:root=MUSIC&path=com.apple.Music:VolumeLimit

TV

  • Settings ⇾ TV: prefs:root=TVAPP

Photos

  • Photos: prefs:root=Photos

Camera

  • Camera: prefs:root=CAMERA
  • Camera ⇾ Record Video: prefs:root=CAMERA&path=Record%20Video
  • Camera ⇾ Record Slo-mo: prefs:root=CAMERA&path=Record%20Slo-mo

Books

  • Books: prefs:root=IBOOKS

Game Center

  • Game Center: prefs:root=GAMECENTER
Iain Smith
  • 9,230
  • 4
  • 50
  • 61
  • this is not working for iOS 14 ..always showing settings instead of path mentioned. any workaround ? – tp2376 Mar 30 '21 at 14:14
  • 5
    yes, i have also same issue with iOS 14 but in my case it is resolved when i remove root prefix. for example instead of "prefs:root=Privacy&path=LOCATION" i have ued "App-prefs:Privacy&path=LOCATION" and it works in iOS 14. – Tejas Patel Jun 25 '21 at 04:56
  • 1
    Does Apple no longer reject the app if we use such configurations? – letsbondiway Dec 13 '22 at 17:32
17

You can use this on iOS 5.0 and later: This no longer works.

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs://"]];
davidcann
  • 1,360
  • 1
  • 15
  • 17
  • Son of a gun, that actually works! I can't find any documentation reference to this. Do you have one? What the behavior of this code under iOS4? Other than failure, what happens? Nothing? – Mark Granoff Oct 18 '11 at 19:14
  • 3
    @MarkGranoff No, it seems to be technically undocumented, but it's not as bad as a normal undocumented API, since it's just a URL Scheme. You can check for it with canOpenURL: first. Also, there's a thread about it here: https://devforums.apple.com/message/543818 – davidcann Oct 18 '11 at 20:23
  • Right! Excellent points. That DevForum thread suggested that undocumented == private API, which means: don't use it (until it's documented. :-) – Mark Granoff Oct 18 '11 at 20:29
  • 3
    You can get to different areas in settings according to [this article](http://forums.tipb.com/iphone-4s-forum/223832-use-siri-access-system-preferences.html). For example this URL will take you to Bluetooth settings `prefs:root=General&path=Bluetooth ` – progrmr Nov 10 '11 at 14:02
  • 1
    I got an application rejected for using private API because I was opening the url: @"prefs:root=Brightness". Usually, un-documented means private. – Guillaume Jan 05 '12 at 18:23
  • 4
    Apple has stated that this wasn't a public API, and is no longer supported. There is a bug filed on this issue, number 11253669. – Don Wilson May 08 '12 at 04:57
  • 2
    I just saw that this works in Strava app. Turn off Bluetooth & then turn it on in app. Then it asks to got to settings app & it goes directly to Bluetooth settings. This is for iOS5.1. Is there a way to find out what scheme they are using? – Ants Dec 01 '12 at 00:57
  • @Ants see http://stackoverflow.com/questions/15682164/iphone-open-settings-from-my-application-ios-6 – Andrei Aug 10 '13 at 09:55
14

iOS 10 update

Apple changed the method to open async on the main thread. However, from now it is only possible to open the app settings in native settings.

[[UIApplication sharedApplication] openURL:url options:@{} completionHandler:nil];

iOS 9 update

It is now possible to go directly to sub-settings menu. However, a URL scheme has to be created. It can be done using two ways:

  1. XCode - You will find it in Target, Info, URL Scheme. Then, just type prefs.
  2. Directly adding to *-Info.plist. Add the following: <key>CFBundleURLTypes</key> <array> <dict> <key>CFBundleTypeRole</key> <string>Editor</string> <key>CFBundleURLSchemes</key> <array> <string>prefs</string> </array> </dict> </array>

Then the code:

Swift

UIApplication.sharedApplication().openURL(NSURL(string:"prefs:root=General&path=Keyboard")!)

Objective-c

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=General&path=Keyboard"]];

guyromb
  • 773
  • 8
  • 15
7

In Swift 3 / iOS 10+ this now looks like

if let url = URL(string: "App-Prefs:root=LOCATION_SERVICES") {
    UIApplication.shared.open(url, completionHandler: .none)
}
Damo
  • 12,840
  • 3
  • 51
  • 62
  • how to get to notification screen? because if let url = URL(string: "App-Prefs:root=NOTIFICATIONS_ID&path=io.artup.artup") { if #available(iOS 10.0, *) { UIApplication.shared.open(url, completionHandler: .none) } } but i went to notification in iPhone 6 not in iPhone 7 plus? – user3804063 Jul 13 '17 at 07:41
  • 3
    This will get your app rejected. They put it under use of private API. – Bersaelor Aug 24 '18 at 08:59
  • I have got rejected my app, using this "App-Prefs:root" – Kiryl Bielašeŭski Oct 09 '18 at 21:21
  • 1
    Just emphasize what others mentioned here, don't use this method, it'll get your app rejected. Repeatedly submitting app with such will get your developer account closed. – CodeBrew Jan 08 '19 at 02:19
5

In Swift 3 all I needed is this (here for example redirect to my app notifications):

if let url = URL(string: "App-Prefs:root=NOTIFICATIONS_ID&path=your app bundleID") {
    if #available(iOS 10.0, *) {
        UIApplication.shared.open(url, completionHandler: .none)
    } else {
        // Fallback on earlier versions
    }
}

Source: phynet gist.

This worked with me only when settings is in background. It will redirect you to your app notification settings but if settings wasn't running in the background it will just redirect you to notification settings in general.

Nathan Tuggy
  • 2,237
  • 27
  • 30
  • 38
ynamao
  • 106
  • 1
  • 16
5

Swift 3:

guard let url = URL(string: UIApplicationOpenSettingsURLString) else {return}
if #available(iOS 10.0, *) {
  UIApplication.shared.open(url, options: [:], completionHandler: nil)
} else {
  // Fallback on earlier versions
  UIApplication.shared.openURL(url)
}
Duy Doan
  • 51
  • 1
  • 5
3

UIApplicationOpenSettingsURLString this will only work if you have previously allowed for any permission. For example Location, Photo, Contact, Push notification access. So if you have not such permission(s) from the user:

If iOS 10 or above,

It will open the Settings but then crash it. The reason, there's nothing in settings for your app.

Below code will open your application settings inside the iOS Setting.

NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
if ([[UIApplication sharedApplication] canOpenURL:url]) {
    [[UIApplication sharedApplication] openURL:url];
}

Due to device unavailability, I couldn't check this on iOS < 10.

Also, I could find below code from some gist and it works fine on iOS 10 as well. But I am not sure if this will approve by Apple review team or not.

https://gist.github.com/johnny77221/bcaa5384a242b64bfd0b8a715f48e69f

Hemang
  • 26,840
  • 19
  • 119
  • 186
3

As openURL(_:) is deprecated after iOS 10.0, use open(_:options:completionHandler:) instead.

if let settingsUrl = URL(string: UIApplication.openSettingsURLString)  {
        UIApplication.shared.open(settingsUrl, options: [:]) { completed in
             if !completed {
                 print("Failed opening")
             }
        }
}
Natasha
  • 6,651
  • 3
  • 36
  • 58
2

You can use the below code for it.

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
Som
  • 128
  • 9
1

Tested with iOS 10. Working

NSArray* urlStrings = @[@"prefs:root=WIFI", @"App-Prefs:root=WIFI"];
for(NSString* urlString in urlStrings){
NSURL* url = [NSURL URLWithString:urlString];
if([[UIApplication sharedApplication] canOpenURL:url]){
    [[UIApplication sharedApplication] openURL:url];
    break;
}
}

Happy Coding :)

  • 3
    This will get your app rejected. Just had it happen to me. – Bersaelor Aug 24 '18 at 08:58
  • Is that so, But this line of code will directly take you to the desired location – Praveen Sharma Sep 05 '18 at 13:24
  • 1
    Yes it will get you there. I'm not saying it doesn't work, I'm just pointing out that it will get you rejected during app review. "prefs:root" is a private url scheme according to what the review team told us. (You might get lucky and they don't notice for a while, we had the feature in for a while and passed several reviews before the reviewer noticed it) – Bersaelor Sep 05 '18 at 16:21
  • Thanks for the information, I would try something else, But right now i am stucked in VPN connectivity, Finding a solution for this. – Praveen Sharma Sep 06 '18 at 12:39
1

SWIFT 4.0

'openURL' was deprecated in iOS 10.0: Please use openURL:options:completionHandler: instead

UIApplication.shared.open(URL.init(string: UIApplicationOpenSettingsURLString)! , options: [:], completionHandler: nil)
Harshil Kotecha
  • 2,846
  • 4
  • 27
  • 41
1

Swift 4

I prefer to open setting in a safer way,

if let settingUrl = URL(string:UIApplicationOpenSettingsURLString) {

    UIApplication.shared.open(settingUrl)
}
else {
    print("Setting URL invalid")
}
Sazzad Hissain Khan
  • 37,929
  • 33
  • 189
  • 256
0

Swift You can use following function to open Settings App with Bluetooth Page

func openSettingsApp(){
    if let settings = NSURL(string: "prefs:root=Bluetooth") {
        UIApplication.sharedApplication().openURL(settings)
    }
}

Again this would not open the App's Settings. This would open settings app with Bluetooth as this is deep linking to bluetooth.

Alok C
  • 2,787
  • 3
  • 25
  • 44
0

To add to accepted answer: (from apple developer documentation) "When you open the URL built from this string (openSettingsURLString), the system launches the Settings app and displays the app’s custom settings, if it has any." So, if you want to open settings for your app, create your own Settings.bundle.

Jovan Stankovic
  • 4,661
  • 4
  • 27
  • 16
0

From iOS 16, you can use openSettingsURLString

if let url = URL(string: UIApplication. openSettingsURLString) {
    await UIApplication.shared.open(url)
}
onmyway133
  • 45,645
  • 31
  • 257
  • 263
-1

Add this to your class,

 public class func showSettingsAlert(title:String,message:String,onVC viewController:UIViewController,onCancel:(()->())?){
            YourClass.show2ButtonsAlert(onVC: viewController, title: title, message: message, button1Title: "Settings", button2Title: "Cancel", onButton1Click: {
                if let settingsURL = NSURL(string: UIApplicationOpenSettingsURLString){
                    UIApplication.sharedApplication().openURL(settingsURL)
                }
                }, onButton2Click: {
                    onCancel?()
            })
        }

 public class func show2ButtonsAlert(onVC viewController:UIViewController,title:String,message:String,button1Title:String,button2Title:String,onButton1Click:(()->())?,onButton2Click:(()->())?){
            dispatch_async(dispatch_get_main_queue()) {
                let alert : UIAlertController = UIAlertController(title: title, message: message, preferredStyle: UIAlertControllerStyle.Alert)

                alert.addAction(UIAlertAction(title: button1Title, style:.Default, handler: { (action:UIAlertAction) in
                    onButton1Click?()
                }))

                alert.addAction(UIAlertAction(title: button2Title, style:.Default, handler: { (action:UIAlertAction) in
                    onButton2Click?()
                }))

                viewController.presentViewController(alert, animated: true, completion: nil)
            }
        }

Call like this,

YourClass.showSettingsAlert("App would like to access camera", message: "App would like to access camera desc", onVC: fromViewController, onCancel: {
  print("canceled")
})
Mohammad Zaid Pathan
  • 16,304
  • 7
  • 99
  • 130