简体   繁体   中英

Open Settings iOS 8 URL

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

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

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 .

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

对于Xamarin.iOS开发人员:

UIApplication.SharedApplication.OpenUrl(new NSUrl(UIApplication.OpenSettingsUrlString));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM