简体   繁体   中英

Add DATE to Xcode xcconfig file

I have an Xcode config file, Config.xcconfig that contains this row only:

BUILD_DATE=`date "+%B %Y"`

I added this configuration to project in correct way, i hope.

在此输入图像描述

I want to use the content of BUILD_DATE variable in the Application-info.plist file. How?

I tried get value using ${BUILD_DATE} but result is the string ``date "+%B %Y"` not the value!

在此输入图像描述

From terminal, result is correct:

alp$ BUILD_DATE=`date "+%B %Y"`
alp$ echo $BUILD_DATE
March 2013
alp$ 

but in Xcode no!

在此输入图像描述

How can i fix this?

You cannot get the build date using the backtick command as the .xcconfig file is not interpreted as a shell script.

Your best bet is to use a similar approach the Bump Build Number script in this SO question (that I asked a while back), which provides a solution for using an external build script to update the .plist file.

For example:

#!/bin/sh

if [ $# -ne 1 ]; then
    echo usage: $0 plist-file
    exit 1
fi

plist="$1"
build_date=$(date "+%B %Y")

/usr/libexec/Plistbuddy -c "Set BUILD_DATE \"$build_date\"" "$plist"

and invoke it from the Xcode Build Script using something like:

"${PROJECT_DIR}/tools/set_build_date.sh" "${PROJECT_DIR}/${INFOPLIST_FILE}"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM