Associate multiple info.plist files with a single target
Asked Answered
G

3

6

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

Gilgai answered 17/12, 2013 at 14:44 Comment(0)
F
6

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

Fissile answered 17/12, 2013 at 14:52 Comment(2)
My attempt is to modularise my properties. I wanted to maintain all the facebook/twitter/pinterest/tumblr ... and all such social metadata in a separate plist. What you're suggesting is selecting a plist file at build time.Gilgai
It is not possible to do this by changing Build Settings, but I see one solution for this. You can ddd script as one of the build phase in Build Phases (to add Editor->Add Build Phase->Add Run Script Build Phase). This script should handle plist connection.Fissile
A
3

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.

Aixlachapelle answered 31/3, 2015 at 21:6 Comment(0)
R
2

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.

Remember answered 17/12, 2013 at 14:57 Comment(1)
could you give a swizzle example using swift 5? I tried this. It does not get called though: public extension NSDictionary { func infoDictionary() -> NSDictionary { print("swizzle?") return NSDictionary() } }Agni

© 2022 - 2024 — McMap. All rights reserved.