New iOS 10 Privacy Permission Settings

James Montemagno

If you’ve ever built an iOS application, you’ll already be familiar with requesting app permissions (and mostly likely are familiar with Android, too, since the Marshmallow release). If an app wanted access to a users location or to use push notifications prior to iOS 10, it would prompt the user to grant permission. iOS10 Graphic

In iOS 10, Apple has changed how most permissions are controlled by requiring developers to declare ahead of time any access to a user’s private data in their Info.plist. In this blog post, you’ll learn how to ensure your existing Xamarin apps continue to work flawlessly with iOS 10’s new permissions policy.

Example iOS 9 Permissions Request

For instance, if we wanted to integrate photos into our application, we would want to request permission with the following code:

PHPhotoLibrary.RequestAuthorization(status =>
{
  switch(status)
  {
    case PHAuthorizationStatus.Authorized:
      break;
    case PHAuthorizationStatus.Denied:
      break;
    case PHAuthorizationStatus.Restricted:
      break;
    default:
      break;
  }
 });

The above code would bring up a dialog box requesting permissions that we could handle, with the message was directly by the system.

What’s New in iOS 10

Starting in iOS 10, nearly all APIs that require requesting authorization and other APIs, such as opening the camera or photo gallery, require a new key value pair to describe their usage in the Info.plist. This is very similar to the requirement for NSLocationWhenInUseUsageDescription or NSLocationAlwaysUsageDescription to be put into the Info.plit when using Geolocation and iBeacon APIs. The difference now is that the application will crash when the app attempts authorization without these keys set. These include use of:

  • Bluetooth Sharing
  • Calendar
  • CallKit/VoIP
  • Camera
  • Contacts
  • Health
  • HomeKit
  • Location
  • Media Library
  • Microphone
  • Motion
  • Photos
  • Reminders
  • Speech Recognition
  • SiriKit
  • TV Provider

These new attributes only take effect when we start compiling against the iOS 10 SDK, which means we must provide keys when using these APIs. If we want to use the Media Plugin for Xamarin and Windows, for example, to take or browse for a photo, we must add the follow privacy settings into the Info.plist file:

properties

When we attempt to pick a photo, our message will be shown to the users:

popup

Each of the privacy keys map to specific values that are set in the Info.plist. Opening it in a text editor, we’ll see the following:

	
NSCameraUsageDescription
This app needs access to the camera to take photos.
NSPhotoLibraryUsageDescription
This app needs access to photos.

Here’s a mapping of each of the values in case you need to manually add them to the Info.plist:

  • Bluetooth Sharing – NSBluetoothPeripheralUsageDescription
  • Calendar – NSCalendarsUsageDescription
  • CallKit – NSVoIPUsageDescription
  • Camera – NSCameraUsageDescription
  • Contacts – NSContactsUsageDescription
  • Health – NSHealthShareUsageDescription & NSHealthUpdateUsageDescription
  • HomeKit – NSHomeKitUsageDescription
  • Location – NSLocationUsageDescription, NSLocationAlwaysUsageDescription, NSLocationWhenInUseUsageDescription
  • Media Library – NSAppleMusicUsageDescription
  • Microphone – NSMicrophoneUsageDescription
  • Motion – NSMotionUsageDescription
  • Photos – NSPhotoLibraryUsageDescription
  • Reminders – NSRemindersUsageDescription
  • Speech Recognition – NSSpeechRecognitionUsageDescription
  • SiriKit – NSSiriUsageDescription
  • TV Provider – NSVideoSubscriberAccountUsageDescription

Learn More

To learn more about these keys, be sure to read through Apple’s Cocoa Keys documentation. To learn more about the new APIs and changes in iOS 10, be sure to read through our Introduction to iOS 10 guide and our new iOS Security and Privacy Enhancements documentation.

0 comments

Discussion is closed.

Feedback usabilla icon