Since iOS 10 and Xcode 8, Apple have added (yet another) security check for our apps. This time it’s about our apps accessing the user’s photo library.
While it was a courtesy to ask the user for permission to use the library before, since iOS 10 we have to add a special key to the app target’s Info.plist file and give a reason why we want to have access.
Here’s how to do it:
Navigate to your project’s target and select the Info tab at the top. In the long list below, hover over any row and click on the little plus icon that comes up. This should add a new row to the table (or in other words, add an entry to the Info.plist file).
Now type in NSPhotoLibraryUsageDescription. It should automatically turn into “Privacy – Photo Library Usage Description”.
On the right hand side of your new row we can add a string value, which will become the description in the dialogue shown in the screenshot above. It seems that we’re free to add whatever we want here, explaining briefly that your app needs access to the user’s photos.
That’s it!
On this note, there are two other keys that may come in handy for accessing the user’s camera and microphone respectively:
- NSCameraUsageDescriptionKey
- NSMicrophoneUsageDescriptionKey
Just as with photos, add these keys and a brief description if your app needs access to either the camera or the microphone. Something like “for image sharing” should do nicely. Here’s what that message looks like in context when iOS presents the dialogue to the user:
The dialogue is shown only once, not every time when the user wants to share an image. Should the user decline, or should s/he want to change this, we should explain to them that this can be done under iOS Settings – Privacy – Photos.
Demo Project
I’ve updated my Demo Project on GitHub with the relevant changes so that it now runs correctly under iOS 10:
For an extensive list of other useful NSkeys, check out this Stack Overflow thread: