By FelipeDev.-


2011-04-13 21:10:29 8 Comments

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"

I really appreciate your answers, I mean it.

15 comments

@Sazzad Hissain Khan 2018-03-20 17:03:48

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

@Harshil 2018-01-29 07:12:16

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)

@Karan Dua 2014-07-25 09:54:00

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

Objective-C:

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

@wjl 2014-09-25 18:41:00

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.

@Paito 2014-10-08 13:32:15

Small correction.. [[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];

@Pavan Kotesh 2014-10-10 15:06:36

@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.

@Paito 2014-10-15 14:35:19

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.

@vbezhenar 2014-11-11 13:57:48

Small Swift correction: UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)

@Tejas K 2016-02-02 10:40:16

@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.

@Praveen Sharma 2017-09-20 10:35:33

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 :)

@Joe 2011-04-13 21:15:10

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

Example:

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

@FelipeDev.- 2011-04-13 21:21:05

thx too much for your answer i have not read in anywhere the thing "supplied by Apple". With that i can convince my client. Thanks!

@Vincent Gable 2011-08-15 20:40:08

If you need a more authoritative answer, you might try asking on the Apple Developer forums <developer.apple.com/devforums/>; or filing a bug at <developer.apple.com/bugreporter/>; — if it's a known issue it should come back as "behaves correctly" or a duplicate of the original bug.

@Nicolas Miari 2012-06-12 15:32:50

Off topic, but your Cyanide & Happiness icon rocks!

@Joe 2013-03-29 11:36:27

I agree if you are willing to bend/break the rules.

@LightningStryk 2014-10-27 14:44:11

This is now possible in iOS 8 using [NSURL URLWithString:UIApplicationOpenSettingsURLString]

@Joe 2014-10-27 19:14:05

Thanks, updated and referenced the other answer.

@PersianBlue 2016-09-23 04:31:22

@Joe This solution is not working for iOS 10 . I am working on Xcode 8, swift 3. Any alternate solution please?

@sohil 2016-10-19 05:55:36

@joe i have worked in iOS 10. its not Works. if any other solution please update your answer.

@Trident 2016-10-21 18:08:45

I think, they still work with Extensions. Ex app is Magic Launcher in Appstore.

@GMHSJ 2016-11-04 15:06:07

in swift 3 - UIApplication.shared.openURL(URL(string:UIApplicationOpenSet‌​tingsURLString)!)

@Raja 2017-07-05 08:36:43

Thank you! It's working fine.

@Duy Doan 2017-06-21 02:12:23

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

@ynamao 2017-04-13 11:36:50

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.

@user3804063 2017-07-13 07:43:39

ynamao : did you find working if not in background

@Damo 2017-03-29 09:48:10

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

@user3804063 2017-07-13 07:41:42

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?

@Alix 2017-02-24 06:36:02

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.

@Hemang 2017-01-17 11:17:03

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

@guyromb 2016-05-25 13:46:41

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"]];

@Mark Peters 2016-09-28 16:08:12

I tried the iOS 10.x solution, and it didn't work for me - nothing happens.

@guyromb 2016-09-28 16:28:13

It works only for app settings apparently

@R.I.Poolak 2016-09-29 10:56:56

@MarkPeters, did you figure out a way yet? It could be of great help. Thanks.

@Mark Peters 2016-09-30 23:01:14

No, I haven't. I still don't know if it is an iOS bug or if Apple just removed the feature.

@Trident 2016-10-21 18:09:39

I think, they still work with Extensions. Ex app is Magic Launcher in Appstore.

@jayant rawat 2017-04-18 11:49:08

it works for ios 10...i m not sure about ios9 though..

@Zaid Pathan 2016-08-12 06:22:50

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

@swiftBoy 2016-03-14 12:05:01

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!!

@Flo 2016-03-17 09:34:55

Thanks, works for me, on iOS 6 and 7, too. Did you try to get it through Apple's review process yet?

@swiftBoy 2016-03-17 09:59:14

@Flo I will let you know, because presently I have pushed for beta testing.

@lorenzoliveto 2016-03-24 07:29:54

Hey @RDC, have you got any news about the review of your app?

@Hlung 2016-04-04 05:19:59

@RDC did your app pass the App Review process?

@ericWasTaken 2016-04-08 21:28:18

iOS 9.3. Worked like a charm. I even see "Back to [my app name]" inside the settings app. Surely, this is supported because I see plenty of other apps that do this kind of thing!

@Shmidt 2016-04-13 16:43:21

That's private API.

@GuiSoySauce 2016-04-26 20:35:22

I am using that and it failed the submission to app store? Anyone else had the same issue or a work around it?

@msg 2016-05-29 13:30:42

@RDC Did Apple approved the build with "prefs" private APIs?

@swiftBoy 2016-05-30 06:07:22

@msg YES!! The application has been approved and available on store.

@msg 2016-05-30 10:01:47

@RDC Thanks for the information

@Maggie Phillips 2016-06-27 05:52:18

From the feedbacks in 2012, using the code 'prefs:' to be rejected, but from this feedback as now in 2016, he says 'approved', Then, hope he be right.

@Gruntcakes 2016-08-05 03:25:57

Unfortunately this doesn't work in iOS 10

@Trident 2016-10-21 18:09:08

I think, they still work with Extensions. Ex app is Magic Launcher in Appstore.

@Drico 2017-02-28 16:17:19

On iOS 10, the new url is not "prefs:root=...." but "App-Prefs:root=...".

@Som 2016-05-31 12:50:47

You can use the below code for it.

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

@davidcann 2011-10-15 16:55:01

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

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

@Mark Granoff 2011-10-18 19:14:31

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?

@davidcann 2011-10-18 20:23:15

@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: devforums.apple.com/message/543818

@Mark Granoff 2011-10-18 20:29:56

Right! Excellent points. That DevForum thread suggested that undocumented == private API, which means: don't use it (until it's documented. :-)

@progrmr 2011-11-10 14:02:12

You can get to different areas in settings according to this article. For example this URL will take you to Bluetooth settings prefs:root=General&path=Bluetooth

@Guillaume 2012-01-05 18:23:27

I got an application rejected for using private API because I was opening the url: @"prefs:root=Brightness". Usually, un-documented means private.

@Zaraki 2012-02-16 05:26:15

This works!!.. but is there any way to open settings of my settings application directly??

@crazywood 2012-03-21 13:21:36

it does not work anymore with sdk ios 5.1 :(

@Don Wilson 2012-05-08 04:57:52

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.

@Ants 2012-12-01 00:57:53

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?

@Andrei 2013-08-10 09:55:36

@Ants 2013-08-21 02:24:14

@Andrei yeah, that explains it thanks.

Related Questions

Sponsored Content

20 Answered Questions

[SOLVED] How do I check if a string contains another string in Objective-C?

32 Answered Questions

[SOLVED] How to change the name of an iOS app?

  • 2008-10-27 03:07:03
  • Robert Gould
  • 414132 View
  • 890 Score
  • 32 Answer
  • Tags:   ios

14 Answered Questions

[SOLVED] How to open Settings programmatically like in Facebook app?

  • 2014-05-23 08:08:52
  • Andrey Chernukha
  • 60730 View
  • 68 Score
  • 14 Answer
  • Tags:   ios objective-c

22 Answered Questions

[SOLVED] How to link to apps on the app store

32 Answered Questions

[SOLVED] Can I embed a custom font in an iPhone application?

  • 2008-12-11 20:21:11
  • Airsource Ltd
  • 230512 View
  • 735 Score
  • 32 Answer
  • Tags:   ios cocoa-touch fonts

2 Answered Questions

[SOLVED] iPhone- Open Settings from my application iOS 6

19 Answered Questions

[SOLVED] Reading settings from app.config or web.config in .net

  • 2009-07-27 16:58:44
  • Russ Clark
  • 717715 View
  • 600 Score
  • 19 Answer
  • Tags:   c# .net appsettings

3 Answered Questions

[SOLVED] Opens apple maps app from ios app with directions

6 Answered Questions

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

2 Answered Questions

[SOLVED] how some apps can open setting app programmatically within their app

Sponsored Content