27

Apple introduced new Privacy settings per app, allowing users to decide if an app is allowed to access the user's Contacts, Calendar, Photos, and Reminders. The user will see an UIAlertView when an app first tries to access one of these resources, similar to the known mechanism when an app wants location access.

It's also possible to set purpose strings, to let the user know why the app wants access. However, this is now done through keys in Info.plist, e.g. "Privacy - Contacts Usage description" (NSContactsUsageDescription) for Contacts.

Now I ask myself how can I localize these values? For the location purpose text, I used to set the purpose property of an CLLocationManager instance with NSLocalizedString(...). How do I do something similar with those new keys in Info.plist?

Addendum: The new privacy keys are listed at the following link, but the summary column does not list them as being localizable: https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html#//apple_ref/doc/uid/TP40009251-SW14

Cœur
  • 37,241
  • 25
  • 195
  • 267
Tafkadasoh
  • 4,667
  • 4
  • 27
  • 31

2 Answers2

47

Add the key to the localized InfoPlist.strings in the supporting files. It should look like this for the purpose:

/* Localized version of location services purpose for Info.plist */
NSLocationUsageDescription = "here is your purpose to use location service";
nevan king
  • 112,709
  • 45
  • 203
  • 241
Gerhard Klauser
  • 486
  • 5
  • 2
  • In case you're still working on a project that was originally created with Xcode 3.x, there is no "InfoPlist.strings" file. So you have to add the file manually to your project. – Tafkadasoh May 16 '13 at 15:40
  • 1
    Find the keys for your given purpose here (last updated February 2014 - use the **key** value in your InfoPlist.strings file or the **Xcode name** in your regular Info.plist file): [Information Property List Key Reference: Cocoa Keys](https://developer.apple.com/library/ios/documentation/general/Reference/InfoPlistKeyReference/Articles/CocoaKeys.html) – leanne May 09 '14 at 19:10
11

You localise your Info.plist by localising the InfoPlist.strings file.

Abizern
  • 146,289
  • 39
  • 203
  • 257
  • Does not work for me. After localizing Info.plist build fails with the following message "could not read data from '/home/username/Git/iOS/AppName/Resources/AppName-Info.plist': The file “AppName-Info.plist” couldn’t be opened because there is no such file." – Tafkadasoh Sep 25 '12 at 14:33
  • That looks like you're trying to open the Info.plist file, not .strings file. The strings files are in their respective localised folder. Have a look at this example https://github.com/Abizern/SimpleLocalisationTesting In the iOS project you can see how I'm using the InfoPlist.strings files in the localised .lproj folders to use different app names for different localisations. – Abizern Sep 25 '12 at 14:47
  • Okay, this works for CFBundleDisplayName, but only in part. The Home screen displays the localized string from InfoPlist.strings, but if I want to query the value programatically with '[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]', this does not work. Regarding the localization of the NSContactsUsageDescription, I can't test if this is working, because the dialog is only displayed once. (reason: Deletion of the App and reinstalling won't let the system forget the user's decision if the app is allowed to access Contacts.) – Tafkadasoh Sep 25 '12 at 16:02
  • Rather than use the NSBundle method to load strings, why not just use the NSLocalizedString macros with the InfoPlist.strings file as the table to use? – Abizern Sep 25 '12 at 16:42
  • As I couldn't test if this works to localize NSContactsUsageDescription until Philipp's answer below, I tried to test it through the NSBundle method. That NSLocalizedString macros would work seemed logical to me, but is this a guarantee that the dialog displays the correct string? IMHO no. However, I could just test it, and your answer works. Will mark it as correct, thank you very much! – Tafkadasoh Sep 26 '12 at 15:10