5

How do we open Settings using the UIApplication.sharedApplication()

What URL should I pass in?

I used the UIApplicationOpenSettingsURLString but it opens directly to the Application specific Settings page. but I would like to have it open the first level of the Settings app.

Or even better, I would like it to open directly to the page where user can enable the Location Services on their phone.

the codes below opens directly to the Application specific Settings page.

UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!);
JayVDiyk
  • 4,277
  • 22
  • 70
  • 135
  • 1
    Possible duplicate of [How to open Settings programmatically like in Facebook app?](http://stackoverflow.com/questions/23824054/how-to-open-settings-programmatically-like-in-facebook-app) – Nishant Oct 26 '15 at 07:09

4 Answers4

4

the answer to this questions is NO, we can't open direct Location page ,but we can open UIApplicationOpenSettingsURLString (settings page)

try this

if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) {
UIApplication.sharedApplication().openURL(appSettings)
}
else
{
 // your URL is invalid
}

for additional information

Community
  • 1
  • 1
Anbu.Karthik
  • 82,064
  • 23
  • 174
  • 143
2

You can use UIRequiresPersistentWiFi to YES in your Info.plist files and create alertview like facebook the user launches your app without a network connection.

To summarize the discussion here:

Step 1: There is no URL you can use to get to the root level of the Settings app.

Step 2: You can send the user to your app's section of the Settings app using UIApplicationOpenSettingsURLString in iOS 8.

Your app can display the same alert as Facebook, which does open the root level of the Settings app, by setting UIRequiresPersistentWiFi to YES.

Rumin
  • 3,787
  • 3
  • 27
  • 30
1

You can open settings apps programmatically try this(works only from iOS8 onwards).

If you are using Swift:

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

If you are using Objective-C

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

For other lower versions(less than iOS8) its not possible to programatically open settings app.

Obj C:

- (void)openSettings
{
    BOOL canOpenSettings = (&UIApplicationOpenSettingsURLString != NULL);

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

Swift:

func openSettings() {
    UIApplication.sharedApplication().openURL(NSURL(string: UIApplicationOpenSettingsURLString)!)
}
Mehul
  • 3,033
  • 23
  • 37
0

For Xamarin.iOS developers:

UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString));
x4h1d
  • 6,042
  • 1
  • 31
  • 46