xcode 将多个 info.plist 文件与单个目标关联

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20637148/
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 04:26:57  来源:igfitidea点击:

Associate multiple info.plist files with a single target

iosxcodeinfo.plist

提问by ScorpionKing2k5

In my iOS project, I've created a separate plist file with values for all social sharing keys and appIds et al.

在我的 iOS 项目中,我创建了一个单独的 plist 文件,其中包含所有社交共享密钥和 appIds 等的值。

How do I specify, in the project/target settings, that this new plist file is an extension of the default info.plist file? Can I create a link in the main info.plist file pointing to the new one?

我如何在项目/目标设置中指定这个新的 plist 文件是默认 info.plist 文件的扩展?我可以在主 info.plist 文件中创建一个指向新文件的链接吗?

Some third party libraries try to look for key-values in the project info.plist file, so I don't have the option to specify the new plist file at the point of reference.

某些第三方库尝试在项目 info.plist 文件中查找键值,因此我无法选择在引用点指定新的 plist 文件。

I was only able to specify one file in the Build Settings > Packaging > Info.plist

我只能在 Build Settings > Packaging > Info.plist 中指定一个文件

回答by pjanecze

As I know you cannot link two plist files. You can only set one plist per target configuration.

据我所知,您不能链接两个 plist 文件。每个目标配置只能设置一个 plist。

Maybe, separating plist files per configuration is what you looking for. To do this go to Build Settings > Packaging > Info.plist File, expand it and set different plist file paths for specified configurations (by default there are 2 configurations: Debug and Release).

也许,将每个配置分开的 plist 文件正是您要寻找的。为此,请转到 Build Settings > Packaging > Info.plist File,将其展开并为指定配置设置不同的 plist 文件路径(默认情况下有 2 个配置:Debug 和 Release)。

回答by eremzeit

As @pjanecze mentioned, you might be able to get what you want by writing a script in a build phase. For example:

正如@pjanecze 所提到的,您可以通过在构建阶段编写脚本来获得所需的内容。例如:

if [ $CONFIGURATION != 'Debug' ]; then
    build_hash=`git log -1 --format="%h"`
    /usr/libexec/PlistBuddy -c "Set :git_sha ${build_hash}" MyInfo.plist
    /usr/libexec/PlistBuddy -c "delete :foobar" MyInfo.plist
fi

You can access more information on how to use PlistBuddyby accessing the man page via man PlistBuddy.

您可以PlistBuddy通过访问手册页来访问有关如何使用的更多信息man PlistBuddy

回答by sergio

As far as I know, there can only be one Info.plist file, specified under Build Settings as you mentioned above.

据我所知,只能有一个 Info.plist 文件,在上面提到的 Build Settings 下指定。

There is a way, though, to manage "extension" plist files relying on the fact that apps access the info.plist file through the - (NSDictionary *)infoDictionarymethod. I.e., you could:

但是,有一种方法可以根据应用程序通过该- (NSDictionary *)infoDictionary方法访问 info.plist 文件这一事实来管理“扩展”plist 文件。也就是说,你可以:

  • swizzle infoDictionarydefault implementation with your own implementation;

  • in your infoDictionaryimplementation, you would call the original implementation, then extend the returned NSDictionaryby reading the "extension" plist files entries.

  • 调酒infoDictionary用自己的实现默认的实现;

  • 在您的infoDictionary实现中,您将调用原始实现,然后NSDictionary通过读取“扩展”plist 文件条目来扩展返回的实现。

You could even define your own special key, e.g., kExtensionPlistFileto be used in Info.plist that point to an "extension" plist file.

您甚至可以定义自己的特殊键,例如,kExtensionPlistFile在指向“扩展”plist 文件的 Info.plist 中使用。