Xcode Script - 从构建设置而不是 info.plist 中获取 Bundle ID [英] Xcode Script - Get Bundle ID from build settings instead of info.plist
问题描述
我正在使用 Receigen 进行 Apple 收据检查.我在构建过程中集成了一个脚本,为我的项目生成适当的文件:
I'm using Receigen for Apple receipt checking. I have integrated a script on my build process that generates the appropriate files for my project:
# Receigen binary
RECEIGEN="/Applications/Receigen.app/Contents/MacOS/Receigen"
# Extract Info.plist information
INPUT="$INFOPLIST_FILE"
BUNDLE_ID=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$INPUT"`
BUNDLE_VERSION=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$INPUT"`
# Expand information if needed
EXPANDED_BUNDLE_ID=`eval "echo $BUNDLE_ID"`
EXPANDED_BUNDLE_VERSION=`eval "echo $BUNDLE_VERSION"`
# Make sure the destination directory exists
mkdir -p "$DERIVED_FILES_DIR"
HEADER="$DERIVED_FILES_DIR/receiptCheck.h"
# Check if the generation is needed
if [ -e "$HEADER" ]; then
SKIP=`grep -q "$EXPANDED_BUNDLE_ID" "$HEADER" && grep -q "$EXPANDED_BUNDLE_VERSION" "$HEADER" && echo "YES"`
fi
# Generate the header file if needed
if [ "x$SKIP" = "x" ]; then
"$RECEIGEN" --identifier "$EXPANDED_BUNDLE_ID" --version "$EXPANDED_BUNDLE_VERSION" --failure 'exitwith173' --success 'runapplication' --os osx > "$HEADER"
fi
Xcode 7 的问题在于这一行:
The problem with Xcode 7 is with this line:
BUNDLE_ID=`/usr/libexec/PlistBuddy -c "Print CFBundleIdentifier" "$INPUT"`
因为新 Xcode 上的 BundleID 位于构建设置而不是 Info.plist 我相信构建设置的关键是 $(PRODUCT_BUNDLE_IDENTIFIER)
Because the BundleID on the new Xcode is on the build settings instead of Info.plist I believe the key on the build settings is $(PRODUCT_BUNDLE_IDENTIFIER)
有没有办法从脚本的构建设置中提取 Bundle Id ?
Is there a way to extract the Bundle Id from the build settings on the script ?
推荐答案
你可以只使用 $PRODUCT_BUNDLE_IDENTIFIER
而不是硬编码 bundle id:
You can just use the $PRODUCT_BUNDLE_IDENTIFIER
instead of hardcoding the bundle id:
EXPANDED_BUNDLE_ID=$PRODUCT_BUNDLE_IDENTIFIER
(请注意,PRODUCT_BUNDLE_IDENTIFIER
周围没有括号).
(Note that there are no parentheses around PRODUCT_BUNDLE_IDENTIFIER
).
然后您可以删除以 BUNDLE_ID=
开头的行,因为它不再需要.
You can then delete the line that starts with BUNDLE_ID=
because it is no longer necessary.
这篇关于Xcode Script - 从构建设置而不是 info.plist 中获取 Bundle ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!