Open App Setting Programmatically

if let url = URL(string:UIApplication.openSettingsURLString)


{ if UIApplication.shared.canOpenURL(url)

{ UIApplication.shared.open(url, options: [:], completionHandler: nil)


}

}


As from apple doc i use above method to open iphone setting from app but unfortuantely its going to app setting rather than IphoneSetting

I am using swift version 4.2 not sure whats the issue

Replies

I tested it in simulator.


It works as described:

- opens the iPhone settings

- then jumps to the app settings inside the iphone settings


Doc says:

openSettingsURLString

Used to create a URL that you can pass to the

openURL(_:)
method. When you open the URL built from this string, the system launches the Settings app and displays the app’s custom settings, if it has any.


>unfortuantely its going to app setting - not sure whats the issue


There is no issue, except with your apparent goal* - as claude notes quoting the docs...your app can only send the user to it's own settings, not the OS's own settings.


*Perhaps if you further described what it is you want to do, exactly, someone can offer specific suggestions, etc. Also, it might help if you picked a better sub-forum, as well. See FAQ4 here:For Best Results - Read the Label


Good luck.

Hi Calude31,


Thank you for your response,


i tried to using

openURL(_:)
still no change in result

You have nothing to change, you get what the API was designed for.


Note that when you tap "'back", you return to the iphone settings.

Thats right but requirement is it should go iphone settings on very first page rather than asking user to click back button

It's the dev's job to correct such 'requirements' - talk to your client/boss, make it clear that it isn't possible, and now that you know, explain what is.

So, use KMT advice, and file an enhancement request.


You may also, in your app, alert user that he/she should first tap on Settings at top left. Tell also how to return to the app, by tapping on app's name at the very top let.

No other way here forn the time being.

>i tried to using

openURL(_:)


BTW, openURL has been deprecated in favor of: open(_:options:completionHandler:) not that is changes the fact your app is not able to casually open Settings.

works for me on iOS 15.0+

UIApplication.shared.open(URL(string: UIApplication.openSettingsURLString)!, options: [:], completionHandler: nil)