更新存档中的 Info.plist 个值

Update Info.plist values in archive

我需要能够在 Xcode ARCHIVE 过程中在 Info.plist 中设置几个自定义值。这是 Xcode 6 和 Xcode 7.

我已经有一个脚本可以成功地将这些值更新为 BUILD 过程中的 post-action。在部署到模拟器或从 Xcode 部署到 phone 时效果很好 6.

但是,在 ARCHIVE 过程中,Info.plist 似乎无法从目录结构中获得。 BUILD 之后,我可以在 $CONFIGURATION-iphoneos 和 $CONFIGURATION-iphonesimulator 的 .../Build/Products 下找到结果。但是在 ARCHIVE 之后,那里什么都没有,我只在 .../Build/Intermediates.

下找到编译后的二进制文件

当然,我可以在 IPA 本身中看到 Info.plist。然而,事后更新和替换此文件的任何尝试均未成功; IPA 不再有效,我假设是由于校验和更改或其他原因。

我不想在源 Info.plist 中更新这些值(例如,使用预操作),因为每次存档时它总是会使源变脏。

想通了。该过程几乎与构建相同——使用 post-action 进行构建,使用 post-action 进行归档——只是路径不同(全部列在下面)找到 Info.plist.

下面是我的构建脚本,其中我使用了要在 Info.plist 中更新的 "name" 和 "value" 的标记。我刚刚复制了这个脚本并将其重命名以用于存档 post-action。请注意,此脚本还有一个从 Info.plist 中提取值的示例,因为我是从客户端版本派生 Web 服务版本。

构建 Info.plist 的路径是以下之一:

"$BUILD_DIR/$CONFIGURATION-iphoneos/$PRODUCT_NAME.app/Info.plist"
"$BUILD_DIR/$CONFIGURATION-iphonesimulator/$PRODUCT_NAME.app/Info.plist"

注意:两个目标都在为一个构建更新,因为我还没有想出一种方法来识别它正在执行哪个构建。

存档 Info.plist 的路径是:

"$ARCHIVE_PRODUCTS_PATH/Applications/$PRODUCT_NAME.app/Info.plist"

构建 post-操作:

$SRCROOT/post_build.sh <value> ~/xcode_build_$PRODUCT_NAME.out

构建脚本:

#!/bin/bash    
# post_build.sh
#
# This script is intended for use by Xcode build process as a post-action.
# It expects the only argument is the value to be updated in Info.plist.  It
# derives the WS version for the URL from the version found in Info.plist.

printf "Running [=13=] using scheme '$SCHEME_NAME' as '$USER'\n"

# If this is a clean operation, just leave
if [ $COPY_PHASE_STRIP == "YES" ]
then
    printf "Doing a clean; exiting.\n"
    exit 1
fi

# Confirm that PlistBuddy is available
PLIST_BUDDY=/usr/libexec/PlistBuddy
if ![-f "$PLIST_BUDDY"]
then
    printf "Unable to access $PLIST_BUDDY\n"
    exit 1
else
    printf "PLIST_BUDDY=$PLIST_BUDDY\n"
fi

# Function to perform the changes
updatePlist()
{
    PLIST_FILE=
    if [ -f "$PLIST_FILE" ]
    then
        printf "Determing WS version...\n"
        if [[ $SCHEME_NAME == *"Local"* ]]
        then
            WS_VER=""
        else
            # Determine the services version
            BUILD_VER=$(${PLIST_BUDDY} -c "Print CFBundleShortVersionString" "$PLIST_FILE")
            WS_VER=$(printf $BUILD_VER | sed 's/\(.*\)\..*//' | sed 's/\./_/g')
        fi

        # Update the plist
        ${PLIST_BUDDY} -c "Set <name> <value>" "$PLIST_FILE"
        printf "Updated plist $PLIST_FILE\n"
    else
        printf "Skipping -- no plist: $PLIST_FILE\n"
    fi
}

# Retrieve the supplied URL
BASE_URL=
printf "BASE_URL=$BASE_URL\n\n"

# Record the environment settings
printenv | sort > ~/xcode_build_$PRODUCT_NAME.env

# Locate the plist in the device build
printf "Checking device build...\n"
updatePlist "$BUILD_DIR/$CONFIGURATION-iphoneos/$PRODUCT_NAME.app/Info.plist"
printf "\n"

# Locate the plist in the simulator build
printf "Checking simulator build...\n"
updatePlist "$BUILD_DIR/$CONFIGURATION-iphonesimulator/$PRODUCT_NAME.app/Info.plist"
printf "\n"