Saturday, 31 August 2013

Xcode build script to create Icon.png and Default.png assets

Xcode build script to create Icon.png and Default.png assets

I am building an application that exists of two different "versions". Each
version has a different layout (different strings, images, colors and
fonts). I accomplished this using macro's: there's one header file (let's
call it Layout.h for now) that is included in all classes. Layout.h
contains a #define statement that determines what version should be built.
If this statement, let's call it DARK_STYLE, is true, DarkStyle.h is
imported. If the statement is false, BrightStyle.h is included. Both
DarkStyle.h and BrightStyle.h contain the same defines, but with different
values. For example:
<DarkStyle.h>
#define TEXT_COLOR [UIColor blackColor]
<BrightStyle.h>
#define TEXT_COLOR [UIColor whiteColor]
So far so good. Now I have come to the point where the application has to
be shipped. Unfortunately, each version has a different app icon and
different splash screen. What I'm trying to do now is to get the app's
Icon.png and Default.png files generated automatically based on the
DARK_STYLE macro from Layout.h using an Xcode build script.
The build script I have at this point is able to determine whether
DARK_STYLE is set to 1 or 0. The next step is the one I have trouble with:
copy the Icon.png and Default.png assets belonging to the dark style to
the application's bundle (the build script is executed after the "Copy
Bundle Resources" phase).
The following does not work:
if find $SRCROOT -name "Layout.h" -exec echo {} \; -exec grep "#define
DARK_STYLE" {} \; -exec grep 1 {} \;
then
# Copy dark style resources and rename them
find $SRCROOT -name "dark_icon.png" -exec cp "{}"
"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/" \;
mv
"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/dark_icon.png"
"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Icon.png"
else
find $SRCROOT -name "bright_icon.png" -exec cp "{}"
"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/" \;
mv
"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/bright_icon.png"
"${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/Icon.png"
fi
What am I missing here?

No comments:

Post a Comment