iOS: You’re Doing Settings Wrong
One of the apparently less known features for iOS 8 and above is the ability to deep link the user into Settings, where they can enable their Location, Notifications, Contacts, Camera, Calendar, HealthKit, etc for your app as needed.
Most apps just have an alert that pops up giving instructions such as “Go to Settings > Privacy > Location > OUR_APP”. The Twitter app, for example, has a more elaborate, nicely styled directions dialog, so I’ll use it as an example here (but again, too many apps have a much worse version of this unfortunately):
So I’m writing this post as a frustrated user hoping that more iOS developers will just deep link directly to settings, especially since it’s so easy!
Ok, so here’s the code for an alert in a Calendar-related app I’m working on that will include an option to take the user into settings:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
func showEventsAcessDeniedAlert() { let alertController = UIAlertController(title: "Sad Face Emoji!", message: "The calendar permission was not authorized. Please enable it in Settings to continue.", preferredStyle: .Alert) let settingsAction = UIAlertAction(title: "Settings", style: .Default) { (alertAction) in // THIS IS WHERE THE MAGIC HAPPENS!!!! if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) { UIApplication.sharedApplication().openURL(appSettings) } } alertController.addAction(settingsAction) let cancelAction = UIAlertAction(title: "Cancel", style: .Cancel, handler: nil) alertController.addAction(cancelAction) presentViewController(alertController, animated: true, completion: nil) } |
And just to point it out once again, this is the only code you need to add to deep link the user into the Settings for your app!
1 2 3 |
if let appSettings = NSURL(string: UIApplicationOpenSettingsURLString) { UIApplication.sharedApplication().openURL(appSettings) } |
So when the user has denied the needed permission, you can now be a lot more like the Swarm app:
When the user clicks “Open Settings”, they’re conveniently take to this screen:
Just adding these 3 lines of codes will improve the user experience for a very important aspect of your app – the need for permissions to be enabled!!! In my case, the user can’t even continue using the app without the Calendar being authorized. So making it the easiest possible for them to change the permissions in Settings is in my best interest. Same thing applies to many other apps out there.
Note: As @jl_hfl points out, this gets even better in iOS 9! The Settings screen will have a back button to take the user directly back into your app! Seriously, there is absolutely no excuse to NOT use this.