LaunchScreen添加动态版本号

版本号

920 发布: 2020/5/2 07:19 本文总阅读量

首先,在LaunchScreen.storyboard添加一个Label

然后设置Document->APP_VERSION 如图:

项目1

接着点击选择工程的target,选择Build Phases,点击+按钮,选择New Run Script Phase,双击新增的条目重命名Update Version(你开心命名什么都可以),然后拖动这条新增的条目放到Copy Bundle Resources之前,这个是我操作完毕的截图:

项目2

项目3

脚本内容:

# Type a script or drag a script file from your workspace to insert its path.
#   ON/OFF Script Toggle (script ON with #, script OFF without #)
#exit 0

#   Increment Build Number Bool (Increment ON with true, increment OFF with false)
shouldIncrement=fale


#   App vesion / Build version constants
sourceFilePath="$PROJECT_DIR/$PROJECT_NAME/Other/Base.lproj/LaunchScreen.storyboard"
versionNumber="$MARKETING_VERSION"
buildNumber="$CURRENT_PROJECT_VERSION"


#   Increment build number
if [ "$shouldIncrement" = true ]; then
    buildNumber=$(($buildNumber + 1))
    /usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
fi

#   Output version & build numbers into a label on LaunchScreen.storyboard
sed -i .bak -e "/userLabel=\"APP_VERSION\"/s/text=\"[^\"]*\"/text=\"version:$versionNumber($buildNumber)\"/" "$sourceFilePath"