简体   繁体   English

如何本地化 NSPhotoLibraryUsageDescription 键 (ALAssets)

[英]How to Localize NSPhotoLibraryUsageDescription key (ALAssets)

I'm trying to localize the NSPhotoLibraryUsageDescription key defined in the application's info.plist file ( reference here ).我正在尝试本地化应用程序的 info.plist 文件( 参考此处)中定义的NSPhotoLibraryUsageDescription键。
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).我正在使用 ALAssetsLibrary 枚举资产组(这会触发访问请求消息弹出)。

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.我想避免本地化整个 info.plist 文件,因为它包含更多非语言环境相关的内容。

Anyone already solved this or have hints how to proceed?任何人已经解决了这个问题或有如何进行的提示?

There is a file you can create (which may be created for you when you create a project) called InfoPlist.strings .您可以创建一个名为InfoPlist.strings的文件(可能会在您创建项目时为您创建)。 This file is used and localized much like the file Localizable.strings .该文件的使用和本地化与文件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注意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.我认为只要该键包含在info.plist ,它就会使用InfoPlist.string的值进行InfoPlist.string如果它适用于该语言)。 Otherwise it will use whatever is defined in info.plist.否则它将使用 info.plist 中定义的任何内容。

I have my note here https://github.com/onmyway133/notes/issues/290 , or you will get我在这里有我的笔记https://github.com/onmyway133/notes/issues/290 ,否则你会得到

Missing Info.plist key - This app attempts to access privacy-sensitive data without a usage description.缺少 Info.plist 键 - 此应用程序尝试访问隐私敏感数据而没有使用说明。 The app's Info.plist must contain an NSPhotoLibraryUsageDescription key with a string value explaining to the user how the app uses this data.应用程序的 Info.plist 必须包含一个 NSPhotoLibraryUsageDescription 键和一个字符串值,向用户解释应用程序如何使用这些数据。 Once these issues have been corrected, you can then redeliver the corrected binary.更正这些问题后,您就可以重新交付更正后的二进制文件。

Make sure确保

  • You declare the keys in Info.plist您在 Info.plist 中声明密钥
  • You localize it in InfoPlist.strings您在 InfoPlist.strings 中对其进行本地化
  • You don't need double quotes, like "NSPhotoLibraryUsageDescription" = "Test of new Photos warnings";你不需要双引号,比如"NSPhotoLibraryUsageDescription" = "Test of new Photos warnings"; , you can just use NSPhotoLibraryUsageDescription = "Test of new Photos warnings"; , 你可以只使用NSPhotoLibraryUsageDescription = "Test of new Photos warnings";

The only way to make this work for me was in Xcode to:使这项工作对我有用的唯一方法是在 Xcode 中:

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

Added language there.在那里添加了语言。 This operation created the <projectName>/<LanguageInitials>.lproj folder.此操作创建了<projectName>/<LanguageInitials>.lproj文件夹。

在此处输入图片说明

2) I created file InfoPlist.strings inside the folder <projectName>/<LanguageInitials>.lproj ; 2)我在文件夹<projectName>/<LanguageInitials>.lproj内创建了文件 InfoPlist.strings ;

3) I added the text: 3)我添加了文字:

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

inside that InfoPlist.strings file.在那个InfoPlist.strings文件中。

4) I then added that folder to the project with File -> add new files to the project or drag and drop. 4) 然后我使用File -> add new files to the project或拖放将该文件夹File -> add new files to the project

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.清理缓存,将模拟器上的语言设置为新的,在模拟器上运行时将scheme中的语言编辑为新的并重新启动模拟器。

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM