Associate multiple info.plist files with a single target

10.1k Views Asked by At

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

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?

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.

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

3

There are 3 best solutions below

2
On

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

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

1
On

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

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

  • swizzle infoDictionary default implementation with your own implementation;

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

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

0
On

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

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 PlistBuddy by accessing the man page via man PlistBuddy.