Location Permissions in iOS Apps (Always or When in Use)

Manish Ahuja
3 min readJan 24, 2017

--

Location services has been one of the most powerful framework/API Apple has provided to the developers, and for that very reason you can find location services being used in most if not all apps we use in a regular basis.

Core Location framework provides developers with multiple ways to track user’s location, and today we’ll discuss two of the most common ways — requesting location access “When in Use” & “Always”. As the name suggests, “When in Use” authorization allows your app to access user’s location when the app is in foreground or active while “Always” authorization allows your app to access user’s location even when it’s in the background.

Without diving too much into details let’s talk about how you can request these permissions in your app. Based on your requirements, you must include these keys in info.plist file:

  • For “Always” authorization include — NSLocationAlwaysUsageDescription”
  • For “When in Use” authorization include — “NSLocationWhenInUseUsageDescription”

Value of these keys should be a text string explaining why you need those permissions in the first place, and the same text string is displayed to users in the alert that is displayed while requesting the permissions. If you fail to add the appropriate key in your info.plist file, user will not be presented with the location prompt.

If my app can access location both in foreground and background, why not always go with that option?

As someone rightly once said, with great power comes great responsiblity, you should request “Always” authorization only when it adds a definite value to your app. Requesting “Always” authorization not only raises privacy concern but accessing user’s location in the background impacts device’s battery too.

Uber recently changed the authorization in the recent update from “When in Use” to “Always”, and that resulted in a huge backlash from the users and tech community.

Uber says it needs location access in the background for improved pickups and dropoffs, customer support and safety purpose.

The only option available to users was to allow “Always” access or they were greeted with the following prompt within the app, and that took away the “ease of use” which I as a Uber user liked most about the app.

So, as a developer what other options do I have? What if I want “Always” access to provide some rich feature in my app, but at the same time giving users an option to go with “When in Use” permissions if they’re concerned about privacy or battery usage and still provide them with a great user experience.

Is it possible to give your users an option to pick between “Always” or “When in Use” authorization?

Fortunately, YES YOU DO!

The first step would be to add both “NSLocationWhenInUseUsageDescription” & “NSLocationAlwaysUsageDescription” keys in your info.plist file. The thing to keep in mind is that user is presented with authorization prompt only once, so you should go ahead and ask “Always” authorization:

CoreLocationManager().requestAlwaysAuthorization

You should be more than happy if user provides you with permission to access location in the background, but unfortunately if user doesn’t allow, you can always prompt user to go to device’s privacy settings and change the authorization to “When in Use”.

You can use “UIApplicationOpenSettingsURLString” to navigate user directly to your app’s settings screen within the settings app.

To wrap up, as a developer we should build apps that provide users with a rich and intuitive experience but at the same time keep their privacy concerns as top priority too and I hope the team at Uber understands this!

--

--