23

I'm trying to localize the NSPhotoLibraryUsageDescription key defined in the application's info.plist file (reference here).
This key gives you a point to provide custom message when the app is first asking for access to your camera roll. I'm using ALAssetsLibrary to enumerate assets groups (which triggers the access request message to pop-up).

So far my googling doesn't answer how I could achieve this.

I want to avoid localizing the whole info.plist file as it contain a lot more non-locale dependent content.

Anyone already solved this or have hints how to proceed?

kr45ko
  • 485
  • 1
  • 3
  • 13
  • 2
    "So far my googling doesn't answer how I could achieve this." And now my Googling brought me here, thanks for asking this! – Dan Rosenstark Nov 13 '16 at 23:15

3 Answers3

49

There is a file you can create (which may be created for you when you create a project) called InfoPlist.strings. This file is used and localized much like the file Localizable.strings.

In it you would have and entry something like:

NSPhotoLibraryUsageDescription = "Test of new Photos warnings";

Note that there are no quotation marks around the key

I think as long as the key is included in info.plist, it will localized using the value in InfoPlist.string if it is available for the language. Otherwise it will use whatever is defined in info.plist.

Bill
  • 38,492
  • 24
  • 114
  • 205
Joe Licari
  • 738
  • 1
  • 7
  • 6
  • 3
    Thank you Joe! :) Perfectly working. Once I got the keyword "InfoPlist" i found [this](http://developer.apple.com/library/ios/#documentation/general/Reference/InfoPlistKeyReference/Articles/AboutInformationPropertyListFiles.html) in Apple docs. Hope this could be helpful to other people too! Regs. – kr45ko Apr 18 '13 at 11:07
  • 1
    FWIW it didn't work for me until I wrapped NSPhotoLibraryUsageDescription in double quotes, too. – capikaw Apr 01 '15 at 16:22
  • If localized, what should the key's value contain in the plist file? – Iulian Onofrei Aug 12 '16 at 12:59
  • @lulian, The localized key's value contains the text string, translated into whatever language you are localizing. – Chris Brewer Aug 12 '16 at 17:04
  • 4
    To be clear: the line above "NSPhotoLibraryUsageDescription" = "..."; needs to be in both the main "Info.plist" file aswell as the localized "InfoPlist.string" files. – Mani Sep 18 '16 at 21:44
3

I have my note here https://github.com/onmyway133/notes/issues/290, or you will get

Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data. Once these issues have been corrected, you can then redeliver the corrected binary.

Make sure

  • You declare the keys in Info.plist
  • You localize it in InfoPlist.strings
  • You don't need double quotes, like "NSPhotoLibraryUsageDescription" = "Test of new Photos warnings";, you can just use NSPhotoLibraryUsageDescription = "Test of new Photos warnings";
onmyway133
  • 38,911
  • 23
  • 231
  • 237
  • 1
    It's not fully clear to me what `You declare the keys in Info.plist` means. Does this mean, just put the `NSCameraUsageDescription` part without the following `This app requires access to the camera` part? – Chris Prince Jul 11 '18 at 23:38
  • 1
    Looks like declare means to redundantly give the key and value in both places. At least for your "primary" language. – Chris Prince Jul 11 '18 at 23:52
1

The only way to make this work for me was in Xcode to:

1) Go to Project target -> Info-> Localization-> Add localization

Added language there. This operation created the <projectName>/<LanguageInitials>.lproj folder.

enter image description here

2) I created file InfoPlist.strings inside the folder <projectName>/<LanguageInitials>.lproj;

3) I added the text:

NSPhotoLibraryUsageDescription = "<Add your translated text here>";

inside that InfoPlist.strings file.

4) I then added that folder to the project with File -> add new files to the project or drag and drop.

Note: to test this I:

Cleaned cache, set the language on simulator to be the new one, edited the language in scheme to be the new one at running on simulator and restarted the simulator.

enter image description here

Florin Dobre
  • 8,025
  • 2
  • 45
  • 68