iOS Authorizations: How and When ?

Wassa Team
Wassa
Published in
3 min readJun 13, 2018

What kind of permissions do you already have in an iOS application ? It is very common for an application to ask for an access to a number of features during its first run: camera, location, media library… However it is recommended to ask them only when necessary and only when the application will use them.

In this article, we will see how and when to ask permission from the user.

How to ask for user permission?

Generally speaking, a permission can have the following status:

  • notDetermined: the user does not have the access authorizations request yet
  • restricted: the app can have restricted permission, for example: parental mode
  • denied: the user has explicitly refused the permission
  • authorized: the user authorized the app to access the feature. The app is free to use the feature when it wants

An application can ask for permission, your application workflow must take it into consideration that the user can update all authorizations from its system settings.

Prerequisite: update the plist

The first mandatory step to request for an access to a feature is to update the plist with the permission key and a small description. For example for the camera, you should add NSCameraUsageDescription and for the location, it should be NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription, etc.

The associated value is a sentence that will be displayed in the system authorization popup. It is necessary to describe as much as possible why you need it. Without adding this description, the application will stop and will not pass Apple validation.

A complet list of keys can be found here:

We will now see a few examples on how to ask for authorization.

Location

First of all, you can ask for 2 different types of authorisation: always or when in use. By default from iOS 10, an application will ask for the “when in use” authorization even if you ask for the “always” permission. This restriction was made to force developer to enable the “always” option only when necessary and to keep the choice for the user.

This type of permission will have 2 authorized status: authorizedAlways or authorizedWhenInUse.

To ask for the location authorization, you only need to use this function, depending on your case:

The current status can be found while calling this function:

Camera

Depending on the class you are using to access the camera (UIImagePickerViewController or AVCaptureDevice), the authorization system will be different for the request. The first one only requests the update of the plist file, the system will automatically prompt the user when the UIViewController is shown. The second will require a call to this function:

However, if you need the authorization status for the camera, the function is the same for the 2 cameras use-case:

Calendar

In the same way you call AVCaptureDevice authorization request, the permission popup is display through the function requestAccess:

And for the authorization status:

Notifications

For the notifications authorization, the UNUserNotificationCenter class is taking care of asking for authorization.

The only different is how you ask for the current status of notifications:

When to ask for permissions ?

Apple’s recommandations are very clear about that:

“Request personal data only when your app clearly needs it.”, Apple, Human Interface Guidelines

Generally speaking, users are more and more suspicious with application asking for permission immediately while they first launch their app, without even having access to the main features. They expect to be asked only when accessing the feature that need authorization. Don’t hesitate to add a step in which you describe why your application needs this authorization.

Do you want to know more about WASSA?

Wassa is an Innovative Digital Agency expert in Indoor Location and Computer Vision. Whether you are looking to help your customers to find their way in a building, enhance the user experience of your products, collect data about your customers or analyze the human traffic and behavior in a location, our Innovation Lab brings scientific expertise to design the most adapted solution to your goals.

Find us on:

· Facebook and Twitter

· LinkedIn

· GitHub

· Our WebSite

--

--

Wassa Team
Wassa
Editor for

Wassa is a company specialized in the design of innovative digital solutions with great added value.