[英]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确保
"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.