Objective C study note

Redirect your app to the System Settings App

When use some functionality related to user’s privacy, say CoreLocation Framework, there would always be a problem that user may deny the app request for their current location and the app cannot work correctly. There is nothing we can make decision for the user, but at least we can help them enable that service easier.

That is the topic today — redirection to the Settings App

There are two types of redirection you want to make: redirect to the ①App Specific Settings Page and ②System Settings Page

①Redirect to App Specific Settings Page

Prior to iOS 8, there is no way to do that. So if you want to back support to iOS 7 , make sure to check the availability

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

Notice that url is actually the @”app settings”, which would directly get you into the page that user can enable the location request

②Redirect to System Settings

Here is the goal we want to achieve. Before user can accept your app’s request for the location service, user may globally disable the location preference, and your app cannot even trigger that request. So we need to do some additional work to make it happen.

First, go the your App’s Target, under Info, there is a section for URL Types.
URL Type Settings

Add this one which just put URL Schemes called “prefs”

Then inside your code, when you want, call (e.g I want to go to the location under privacy on Settings)

[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"prefs:root=Privacy&path=LOCATION"]];

And that’s it!

This method should be okay to use after iOS5.1, I tested on iOS8.4 and iOS 9 it works great! Any feed back is very appreciated!


One thought on “Redirect your app to the System Settings App

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s