{"id":33781,"date":"2017-10-18T13:24:59","date_gmt":"2017-10-18T20:24:59","guid":{"rendered":"https:\/\/blog.xamarin.com\/?p=33781"},"modified":"2019-04-04T07:48:13","modified_gmt":"2019-04-04T14:48:13","slug":"plugin-permission-changes-ios-11","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/plugin-permission-changes-ios-11\/","title":{"rendered":"Plugin and Permission Changes with iOS 11"},"content":{"rendered":"<p>\t\t\t\tiOS 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&#8217;s <code>Output<\/code>, I noticed a message explaining exactly what I missed!<\/p>\n<pre class=\"wrap:true lang:xhtml decode:true \">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.<\/pre>\n<p>What does that mean for your applications and how does it relate to any Plugins you might be using? This post explains what I&#8217;ve discovered while using two very common Plugins, <code>Xam.Plugin.Geolocator<\/code> and <code>Xam.Plugin.Media<\/code>.<\/p>\n<h2>Changes to Location Permissions<\/h2>\n<p>Developers that need access background location updates are required to include both <code>NSLocationWhenInUseUsageDescription<\/code> and <code>NSLocationAlwaysAndWhenInUseUsageDescription<\/code> in their <code>info.plist<\/code> file with iOS 11 if they are using the <code>NSLocationAlwaysUsageDescription<\/code> key. The <code>NSLocationAlwaysAndWhenInUsageDescription<\/code> 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 <strong>When in Use<\/strong> access level. Then, after some time during which trust is gained, the application can more confidently request the <strong>Always<\/strong> level of access. It&#8217;s important to note that apps can only request the <strong>Always<\/strong> level once.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-33824\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/comparison.png\" alt=\"\" width=\"599\" height=\"632\" \/><\/p>\n<p>Here&#8217;s what the relevant part of the updated <code>info.plist<\/code> file looks like using the Geolocator sample application:<\/p>\n<pre class=\"lang:xhtml decode:true\">&lt;key&gt;NSLocationAlwaysUsageDescription&lt;\/key&gt;\n&lt;string&gt;Need location for geolocator plugin.&lt;\/string&gt;\n\n&lt;key&gt;NSLocationAlwaysAndWhenInUseUsageDescription&lt;\/key&gt;\n&lt;string&gt;Need location for geolocator plugin.&lt;\/string&gt;\n\n&lt;key&gt;NSLocationWhenInUseUsageDescription&lt;\/key&gt;\n&lt;string&gt;Need location for geolocator plugin.&lt;\/string&gt;<\/pre>\n<h2>Changes to Photo Permissions<\/h2>\n<p>There was a single key, <code>NSPhotoLibraryUsageDescription<\/code>, needed in the <code>info.plist<\/code> in previous versions of iOS for accessing the user&#8217;s Photo Library. iOS 11 added a new key to separate Write-only access from Read access. The new <code>NSPhotoLibraryAddUsageDescription<\/code> key is required if your app needs to save images to the Photo Library while the old <code> NSPhotoLibraryUsageDescription<\/code> key is required for reading an image from the Photo Library.<\/p>\n<h2>Update Your Xamarin Plugins<\/h2>\n<p>The <a href=\"https:\/\/www.xamarin.com\/plugins\">Xamarin Plugins<\/a> have been very popular in the community ever since they were announced.\u00a0The <a href=\"https:\/\/github.com\/jamesmontemagno\/GeolocatorPlugin\">Geolocator<\/a>, <a href=\"https:\/\/github.com\/jamesmontemagno\/MediaPlugin\">Media<\/a> and <a href=\"https:\/\/github.com\/jamesmontemagno\/PermissionsPlugin\">Permissions<\/a> plugins are ready for your apps and iOS 11. If your not familiar with Plugins, be sure to check out the <a href=\"https:\/\/developer.xamarin.com\/guides\/xamarin-forms\/platform-features\/plugins\/\">guide in the Xamarin Developer Center<\/a> where you can learn more about which ones are available and how to create them. <\/p>\n<p><a href=\"https:\/\/forums.xamarin.com\/105253\">Discuss this post on the forums.<\/a>\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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&#8217;s Output, I noticed a message explaining exactly what I [&hellip;]<\/p>\n","protected":false},"author":557,"featured_media":33824,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[6,4],"class_list":["post-33781","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-ios","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>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&#8217;s Output, I noticed a message explaining exactly what I [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/33781","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/users\/557"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=33781"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/33781\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/media?parent=33781"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=33781"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=33781"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}