{"id":27692,"date":"2016-09-19T11:49:21","date_gmt":"2016-09-19T18:49:21","guid":{"rendered":"https:\/\/blog.xamarin.com\/?p=27692"},"modified":"2019-04-04T09:03:05","modified_gmt":"2019-04-04T16:03:05","slug":"new-ios-10-privacy-permission-settings","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/xamarin\/new-ios-10-privacy-permission-settings\/","title":{"rendered":"New iOS 10 Privacy Permission Settings"},"content":{"rendered":"<p>\t\t\t\tIf you&#8217;ve ever built an iOS application, you&#8217;ll already be familiar with requesting app permissions (and mostly likely are familiar with <a href=\"https:\/\/blog.xamarin.com\/requesting-runtime-permissions-in-android-marshmallow\/\">Android, too, since the Marshmallow release<\/a>). 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. <img decoding=\"async\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/ios10.jpg\" alt=\"iOS10 Graphic\" width=\"90\" height=\"90\" class=\"alignright size-full wp-image-27578\" \/><\/p>\n<p>In iOS 10, Apple has changed how most permissions are controlled by requiring developers to declare ahead of time any access to a user&#8217;s private data in their Info.plist. In this blog post, you&#8217;ll learn how to ensure your existing Xamarin apps continue to work flawlessly with iOS 10&#8217;s new permissions policy.<\/p>\n<h4>Example iOS 9 Permissions Request<\/h4>\n<p>For instance, if we wanted to integrate photos into our application, we would want to request permission with the following code:<\/p>\n<pre class=\"theme:vs2012 lang:csharp decode:true\">PHPhotoLibrary.RequestAuthorization(status =&gt;\n{\n  switch(status)\n  {\n    case PHAuthorizationStatus.Authorized:\n      break;\n    case PHAuthorizationStatus.Denied:\n      break;\n    case PHAuthorizationStatus.Restricted:\n      break;\n    default:\n      break;\n  }\n });\n<\/pre>\n<p>The above code would bring up a dialog box requesting permissions that we could handle, with the message was directly by the system. <\/p>\n<h4>What&#8217;s New in iOS 10<\/h4>\n<p>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:<\/p>\n<ul>\n<li>Bluetooth Sharing<\/li>\n<li>Calendar<\/li>\n<li>CallKit\/VoIP<\/li>\n<li>Camera<\/li>\n<li>Contacts<\/li>\n<li>Health<\/li>\n<li>HomeKit<\/li>\n<li>Location<\/li>\n<li>Media Library<\/li>\n<li>Microphone<\/li>\n<li>Motion<\/li>\n<li>Photos<\/li>\n<li>Reminders<\/li>\n<li>Speech Recognition<\/li>\n<li>SiriKit<\/li>\n<li>TV Provider<\/li>\n<\/ul>\n<p>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 <a href=\"https:\/\/blog.xamarin.com\/getting-started-with-the-media-plugin-for-xamarin\/\">Media Plugin for Xamarin and Windows<\/a>, for example, to take or browse for a photo, we must add the follow privacy settings into the Info.plist file:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-27693\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/Properties.png\" alt=\"properties\" width=\"593\" height=\"719\" \/><\/p>\n<p>When we attempt to pick a photo, our message will be shown to the users:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-27694\" src=\"https:\/\/devblogs.microsoft.com\/wp-content\/uploads\/sites\/44\/2019\/03\/PopUp.png\" alt=\"popup\" width=\"438\" height=\"242\" \/><\/p>\n<p>Each of the privacy keys map to specific values that are set in the Info.plist. Opening it in a text editor, we&#8217;ll see the following:<\/p>\n<pre class=\"theme:vs2012 lang:csharp decode:true\">\t\nNSCameraUsageDescription\nThis app needs access to the camera to take photos.\nNSPhotoLibraryUsageDescription\nThis app needs access to photos.\n<\/pre>\n<p>Here&#8217;s a mapping of each of the values in case you need to manually add them to the Info.plist:<\/p>\n<ul>\n<li>Bluetooth Sharing &#8211; NSBluetoothPeripheralUsageDescription<\/li>\n<li>Calendar &#8211; NSCalendarsUsageDescription<\/li>\n<li>CallKit &#8211; NSVoIPUsageDescription<\/li>\n<li>Camera &#8211; NSCameraUsageDescription<\/li>\n<li>Contacts &#8211; NSContactsUsageDescription<\/li>\n<li>Health &#8211; NSHealthShareUsageDescription &amp; NSHealthUpdateUsageDescription<\/li>\n<li>HomeKit &#8211; NSHomeKitUsageDescription<\/li>\n<li>Location &#8211; NSLocationUsageDescription, NSLocationAlwaysUsageDescription, NSLocationWhenInUseUsageDescription<\/li>\n<li>Media Library &#8211; NSAppleMusicUsageDescription<\/li>\n<li>Microphone &#8211; NSMicrophoneUsageDescription<\/li>\n<li>Motion &#8211; NSMotionUsageDescription<\/li>\n<li>Photos &#8211; NSPhotoLibraryUsageDescription<\/li>\n<li>Reminders &#8211; NSRemindersUsageDescription<\/li>\n<li>Speech Recognition &#8211; NSSpeechRecognitionUsageDescription<\/li>\n<li>SiriKit &#8211; NSSiriUsageDescription<\/li>\n<li>TV Provider &#8211; NSVideoSubscriberAccountUsageDescription<\/li>\n<\/ul>\n<h2>Learn More<\/h2>\n<p>To learn more about these keys, be sure to read through <a href=\"https:\/\/developer.apple.com\/library\/content\/documentation\/General\/Reference\/InfoPlistKeyReference\/Articles\/CocoaKeys.html\">Apple&#8217;s Cocoa Keys<\/a> documentation. To learn more about the new APIs and changes in iOS 10, be sure to read through our <a href=\"https:\/\/developer.xamarin.com\/guides\/ios\/platform_features\/introduction-to-ios10\/\">Introduction to iOS 10 guide<\/a> and our new <a href=\"https:\/\/developer.xamarin.com\/guides\/ios\/platform_features\/introduction-to-ios10\/security-privacy-enhancements\/\">iOS Security and Privacy Enhancements documentation<\/a>.\t\t<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you&#8217;ve ever built an iOS application, you&#8217;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. In iOS [&hellip;]<\/p>\n","protected":false},"author":544,"featured_media":27694,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2],"tags":[6,4],"class_list":["post-27692","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-developers","tag-ios","tag-xamarin-platform"],"acf":[],"blog_post_summary":"<p>If you&#8217;ve ever built an iOS application, you&#8217;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. In iOS [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/27692","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\/544"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/comments?post=27692"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/posts\/27692\/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=27692"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/categories?post=27692"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/xamarin\/wp-json\/wp\/v2\/tags?post=27692"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}