简体   繁体   English

如何使用简单的字符串更改自定义 Info.plist 键

[英]how can I change custom Info.plist key with simple string

I wanna add a custom key to info.plist file but **Apple** says it should be unique.我想在info.plist文件中添加一个自定义键,但**Apple**说它应该是唯一的。 so I add the key as **NSCustomKeyName** or **ZSCustomKeyName**.所以我将密钥添加为**NSCustomKeyName****ZSCustomKeyName**. but it should be read "Custom Key" when I do Open As->Property List.但是当我打开As->Property List 时,它应该被读取为"Custom Key" but it stays same as **NSCustomKeyName** or **ZSCustomKeyName** .但它与**NSCustomKeyName****ZSCustomKeyName**相同。 how can I do that?.我怎样才能做到这一点?。 I mean how can I convert **CFBundleName** key to **" Bundle name"** .我的意思是如何将**CFBundleName**键转换为**" Bundle name"**

The key-name / Property List name "translation" is done by Xcode via an internal lookup table.键名/属性列表名称“翻译”由 Xcode 通过内部查找表完成。 It's not simply a "strip the prefix and put spaces before upper-case letters" process.这不仅仅是一个“去掉前缀并在大写字母前放置空格”的过程。

For example, when viewing as source, you may have this key:例如,当作为源查看时,您可能有这个键:

<key>NSCameraUsageDescription</key>

which, when viewed as a Property List shows as:其中,当作为属性列表查看时,显示为:

Privacy - Camera Usage Description

If you want to add your own "custom" keys, you are not required to use a prefix... that's just an easy way to make sure they're unique.如果您想添加自己的“自定义”键,则不需要使用前缀......这只是确保它们唯一的一种简单方法。

For example, source view:例如,源视图:

<key>My Key</key>
<string>My Value</string>

will show in Property List view as:将在属性列表视图中显示为:

My Key          | My Value

and can be accessed with:并且可以通过以下方式访问:

Bundle.main.infoDictionary?["My Key"]

If I prefix that as:如果我将其前缀为:

com.donmag.My Key

That's how it will show up in Property List view, and I would have to access it with:这就是它在属性列表视图中的显示方式,我必须通过以下方式访问它:

Bundle.main.infoDictionary?["com.donmag.My Key"]

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

相关问题 如何在Info.plist中读取自定义键的值并在Xcode的构建设置中使用它? - How can I read a custom key's value in Info.plist and use it in Xcode's build settings? 我可以在另一个Info.plist键值的内部使用Info.plist中一个键的值吗? - Can I use the value for one key in Info.plist inside the value of another Info.plist key? 我可以在 info.plist 定义用户定义的键吗 - Can i define User Defined key at info.plist 如何将自定义条目添加到 iOS watchKit 扩展 info.plist 中? - How can I add custom entries into iOS watchKit extension info.plist? iOS:如何在Info.plist的“打开方式”操作表中更改应用程序名称? - iOS: How can I change the app name in the Open-With action sheet in Info.plist? 如何将 NSAppTransportSecurity 添加到我的 info.plist 文件中? - How can I add NSAppTransportSecurity to my info.plist file? 如何将NSExtension和UNNotificationExtensionCategory键添加到Info.plist? - How can I add the NSExtension & UNNotificationExtensionCategory keys to Info.plist? 应用程序因Info.plist文件麦克风中缺少目的字符串而被拒绝,但我无法在info.plist中添加说明 - App got rejected for missing Purpose String in Info.plist File Microphone, but I can't add the description in info.plist 我可以将 info.plist 视为资产吗? - can i treat info.plist as an asset? 缺少Info.plist键 - Missing Info.plist key
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM