Plugin and Permission Changes with iOS 11

John Miller

iOS 11 introduced some fun updates around permissions when accessing certain features on the device. I first noticed these changes when trying to access a user location with the Geolocator Plugin in a Xamarin.Forms application. To my surprise, nothing happened. Upon further investigation of the application’s Output, I noticed a message explaining exactly what I missed!

This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain both NSLocationAlwaysAndWhenInUseUsageDescription and NSLocationWhenInUseUsageDescription keys with stringvalues explaining to the user how the app uses this data.

What does that mean for your applications and how does it relate to any Plugins you might be using? This post explains what I’ve discovered while using two very common Plugins, Xam.Plugin.Geolocator and Xam.Plugin.Media.

Changes to Location Permissions

Developers that need access background location updates are required to include both NSLocationWhenInUseUsageDescription and NSLocationAlwaysAndWhenInUseUsageDescription in their info.plist file with iOS 11 if they are using the NSLocationAlwaysUsageDescription key. The NSLocationAlwaysAndWhenInUsageDescription key is new for iOS 11 and helps developers with a new recommended approach for requesting permissions. Apple recommends that applications first request permission for location usage with the When in Use access level. Then, after some time during which trust is gained, the application can more confidently request the Always level of access. It’s important to note that apps can only request the Always level once.

Here’s what the relevant part of the updated info.plist file looks like using the Geolocator sample application:

<key>NSLocationAlwaysUsageDescription</key>
<string>Need location for geolocator plugin.</string>

<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
<string>Need location for geolocator plugin.</string>

<key>NSLocationWhenInUseUsageDescription</key>
<string>Need location for geolocator plugin.</string>

Changes to Photo Permissions

There was a single key, NSPhotoLibraryUsageDescription, needed in the info.plist in previous versions of iOS for accessing the user’s Photo Library. iOS 11 added a new key to separate Write-only access from Read access. The new NSPhotoLibraryAddUsageDescription key is required if your app needs to save images to the Photo Library while the old NSPhotoLibraryUsageDescription key is required for reading an image from the Photo Library.

Update Your Xamarin Plugins

The Xamarin Plugins have been very popular in the community ever since they were announced. The Geolocator, Media and Permissions plugins are ready for your apps and iOS 11. If your not familiar with Plugins, be sure to check out the guide in the Xamarin Developer Center where you can learn more about which ones are available and how to create them.

Discuss this post on the forums.

0 comments

Discussion is closed.

Feedback usabilla icon