xcode 如何本地化 NSPhotoLibraryUsageDescription 键 (ALAssets)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15881534/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 03:09:31  来源:igfitidea点击:

How to Localize NSPhotoLibraryUsageDescription key (ALAssets)

iphonexcodeios6alassetslibrary

提问by kr45ko

I'm trying to localize the NSPhotoLibraryUsageDescriptionkey 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).

我正在尝试本地化应用程序的 info.plist 文件(参考此处)中定义的NSPhotoLibraryUsageDescription键。 当应用程序首次要求访问您的相机胶卷时,此键可让您提供自定义消息。我正在使用 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?

任何人已经解决了这个问题或有如何进行的提示?

回答by Joe Licari

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.

您可以创建一个名为InfoPlist.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.stringif it is available for the language. Otherwise it will use whatever is defined in info.plist.

我认为只要键包含在 中info.plistInfoPlist.string如果它可用于该语言,它将使用值进行本地化。否则它将使用 info.plist 中定义的任何内容。

回答by onmyway133

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. 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.

缺少 Info.plist 键 - 此应用程序尝试访问隐私敏感数据而没有使用说明。应用程序的 Info.plist 必须包含一个 NSPhotoLibraryUsageDescription 键和一个字符串值,向用户解释应用程序如何使用这些数据。更正这些问题后,您就可以重新交付更正后的二进制文件。

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";
  • 您在 Info.plist 中声明密钥
  • 您在 InfoPlist.strings 中对其进行本地化
  • 你不需要双引号,比如"NSPhotoLibraryUsageDescription" = "Test of new Photos warnings";,你可以使用NSPhotoLibraryUsageDescription = "Test of new Photos warnings";

回答by Florin Dobre

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>.lprojfolder.

在那里添加了语言。此操作创建了<projectName>/<LanguageInitials>.lproj文件夹。

enter image description here

在此处输入图片说明

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

2)我在文件夹中创建了文件 InfoPlist.strings <projectName>/<LanguageInitials>.lproj

3) I added the text:

3)我添加了文字:

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

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

inside that InfoPlist.stringsfile.

在那个InfoPlist.strings文件里面。

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

4)然后我使用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中的语言编辑为新的并重新启动模拟器。

enter image description here

在此处输入图片说明