MTSlive
MTSlive

Reputation: 71

Access Settings app in iOS

Is there an opportinity to show up the settings.app in iOS by clicking on a button? It should work with iOS 5.1 so the "prefs:root..." url is no option.

Do you have an idea how to solve this?

Upvotes: 7

Views: 7290

Answers (5)

Will Ullrich
Will Ullrich

Reputation: 2238

The method openURL: is now deprecated.


iOS 10 +

The correct way to open the settings URL (or any URL for that matter) is as follows:

NSURL *settingsURL = [NSURL URLWithString:UIApplicationOpenSettingsURLString];

[[UIApplication sharedApplication] openURL:settingsURL options:@{} completionHandler:^(BOOL success) {

    // Do anything here 
                    
}];

Upvotes: 0

Banker Mittal
Banker Mittal

Reputation: 1918

On iOS 8 Apple gave us the possibility to go to the App Settings right from our app

you can apply this code:

- (IBAction)openSettings:(id)sender {
    BOOL canOpenSettings = (UIApplicationOpenSettingsURLString != NULL);
    if (canOpenSettings) {
        NSURL *url = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
        [[UIApplication sharedApplication] openURL:url];
    }
}

Upvotes: 1

djibouti33
djibouti33

Reputation: 12132

I know the question is about 5.1 specifically, but in case anyone else is interested:

As of iOS 8, it is possible to take a user from your app directly into the Settings app. They will be deep linked into your app's specific Settings page, but they can back out into the top level Settings screen.

UPDATE:

Thanks to Pavel's comment, I simplified the if statement and avoided the EXC_BAD_ACCESS on iOS 7.

UPDATE 2:

If your deployment target is set to 8.0 or above, Xcode 6.3 will give you the following warning:

Comparison of address of 'UIApplicationOpenSettingsURLString' not equal to a null pointer is always true

This is because the feature was available starting in 8.0, so this pointer will never be NULL. If your deployment target is 8.0+, just remove the if statement below.

if (&UIApplicationOpenSettingsURLString != NULL) {
    NSURL *appSettings = [NSURL URLWithString:UIApplicationOpenSettingsURLString];
    [[UIApplication sharedApplication] openURL:appSettings];
} 

Upvotes: 9

apostleofzion
apostleofzion

Reputation: 93

iOS6 shows an option to open the settings app directly from an 'AlertView' (shown automatically) if it detects if you're trying to post to FB or Twitter without having those accounts setup.

I have elaborated this over here

Upvotes: 0

Hailei
Hailei

Reputation: 42153

You are not able to do this on iOS 5.1. Most likely Apple removed that ability intentionally (you'll get "Please enter a valid URL", while Twitter can still call the Settings, though). Please refer to:

Upvotes: 4

Related Questions