gpt4 book ai didi

ios - 尝试读取 InfoPlist.strings 文件...获取 key (?)

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:54:41 26 4
gpt4 key购买 nike

许多人不知道,在 iOS 和 OSX 上本地化应用程序名称的方法是将 InfoPlist.strings 文件添加到包中并本地化该文件。人们将此文件与 Info.Plist 文件混合使用。本地化不是在 Info.plist 中完成的,而是在 InfoPlist.strings 文件中完成的。

也就是说,我已经用两个键创建了这个文件:CFBundleDisplayNameCFBundleName,一如既往。这非常有效,您可以在不同的本地化版本中为您的应用程序定义不同的名称。该文件可以无缝运行。您什么都不用做,只需将文件添加到项目并对其进行本地化。

InfoPlist.strings 是这样的字符串文件:

"CFBundleDisplayName" = "My Localized App Name";
"CFBundleName" = "My Localized App Name";

特别是对于这个项目,我还必须在运行时读取 CFBundleDisplayName 的值。

我试过使用这段代码:

NSString *appName = [[NSBundle mainBundle] localizedStringForKey:@"CFBundleDisplayName" value:nil table:@"InfoPlist"];

读取 CFBundleDisplayName 键,但我得到的值是 CFBundleDisplayName。换句话说,我提供 key 并接收回 key ,而不是值。我应该收到 My Localized App Name

我错过了什么?

最佳答案

我在 Swift 中完全做到了这一点,它按预期工作。

let appname = NSBundle.mainBundle().localizedStringForKey("CFBundleDisplayName", value: nil, table: "InfoPlist")

但是,如果我从相应的 InfoPlist.strings 文件中删除去本地化字符串,它会返回 "CFBundleDisplayName"

因此,请检查您的 .strings 文件中是否遗漏了什么

After trying several possibilities..

BUG 是“项目中的 InfoPlist.strings 的第二个副本”

关于ios - 尝试读取 InfoPlist.strings 文件...获取 key (?),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35348982/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com