How to link directly to your app’s Settings section

Screen Shot 2015-09-24 at 09.37.14

iOS 8 introduced a new UIApplication method that lets us deeply link to our own app’s section in the iOS Settings app. Previously users had to open the Settings app and hunt for the relevant section, which isn’t always easy to find.

To make use of this handy function, add a Settings.bundle to your app (if you don’t already have one), then open the Settings app with the following method:

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

It looks a bit complicated because we’re using three methods in one. We could also write those out to make it a bit easier to understand:

NSString *settings = UIApplicationOpenSettingsURLString;
NSURL *settingsURL = [NSURL URLWithString:settings];
[[UIApplication sharedApplication]openURL:settingsURL];

In essence we call openURL on UIApplication, with a URL which is defined in an enum constant (UIApplicationOpenSettingsURLString). The latter needs to be converted into a URL via the NSURL method URLwithString. Call this method and iOS will transition to the correct section in the Settings app.

Xcode / Simulator Bug

Note that there is a bug in Xcode that makes the Settings section sometimes show up empty. You can trigger this bug if you deploy from Xcode to Simulator or a real device and then execute this code. You must reboot Simulator or your device for the correctly populated Settings section to show up again.

To prevent any panic attacks from happening, deploy the app from Xcode and stop it. Head back to the app and trigger your method to execute the code. Only then will the section show up as it should. In a real world scenario this isn’t an issue because users won’t ever start your app directly from Xcode.

Leave a Reply