Reputation: 4502
We use a library that requires config values to be set in an Okta.plist
file.
As our app has 3 environments, we have config per environment within .xcconfig
files.
This allows us to set things like app icon, app name etc etc depending on the build type (dev, test, release).
I'd like to use those values within Okta.plist
also, so I can configure the instance of Okta we use, however I can't seem to set those values using the config file.
In the case of our Info.plist
we simple reference the value:
/// Release.xcconfig
...
APP_DISPLAY_NAME = Some Text
...
/// Info.plist
<key>CFBundleDisplayName</key>
<string>${APP_DISPLAY_NAME}</string>
And it works.
How can I achieve the same with Okta.plist
? I tried the same approach however it use the key as the value, not the value from the config file.
Upvotes: 3
Views: 897
Reputation: 1688
All build settings(as declared in xcconfig files) are available as environment variables during the build phase script. Referencing those is only supported in info.plist
, if you what to do this in any plist you must write a custom script that will perform the replacement and add it as a build phase script.
You can use the following script Replaceplistenvironmentvariables.swift. This script takes an input & an output plist and will replace all reference to environment variables in the input plist with their value and write to the output plist.
Variable references must be in the following form:
<string>$(A_VARIABLE)</string>
To add this to our project follow the steps
/usr/bin/xcrun --sdk macosx swift "${PROJECT_DIR}/replacePlistEnvironmentVariables.swift" "${SCRIPT_INPUT_FILE_0}" "${SCRIPT_OUTPUT_FILE_0}"
SCRIPT_INPUT_FILE_0=$(SRCROOT)/MyProject/Config.plist
SCRIPT_OUTPUT_FILE_0=${TARGET_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Config.plist
Upvotes: 2