克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

开发过程中,需要给测试提供测试包,经常会遇到因为使用老包导致已修复的问题被标记为未解决,为了快速定位使用的版本号,想到在每次版本号改变的时候,把版本号添加到图标上,这样就能很明确区分是否使用了正确的版本。

原理:

  1. 找到Assets.xcassets里面的图标,并把图标复制到指定目录保存(方便回退)。
  2. 找到当前项目版本号,并记录保存。
  3. 使用imageMagick的convert处理图片。

1.安装imagemagick

brew install imagemagick

2.安装ghostscript

brew install ghostscript

3.把脚本放到项目目录下

01

4.添加脚本

02

5.编译项目

编译后脚本里会新增一个文件夹和一个文件。文件夹用来保存原始的图标,方便回退。文件保存当前编译的版本号,避免每次编译都重复添加。 03

6.完整脚本如下:

#!/bin/bash
#created by leo

echo "=== begin icon add version"
pwd
CURRENT_PATH=`cd $(dirname $0); pwd -P`
cd $CURRENT_PATH
pwd

convert_path=`which convert`
gs_path=`which gs`

if [[ ! -f ${convert_path} || -z ${convert_path} ]]; then
  convert_valid=true;
else
  convert_valid=false;
fi

if [[ ! -f ${gs_path} || -z ${gs_path} ]]; then
  gs_valid=true;
else
  gs_valid=false;
fi

if [[ "$convert_valid" = true || "$gs_valid" = true ]]; then
  echo "WARNING: skip icon version, you need to install ImageMagick and ghostscript (fonts) first, you can use brew to simplify process:"

  if [[ "$convert_valid" = true ]]; then
    echo "brew install imagemagick"
  fi
  if [[ "$gs_valid" = true ]]; then
    echo "brew install ghostscript"
  fi
exit 0;
fi

version=`/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"`
build_num=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${CONFIGURATION_BUILD_DIR}/${INFOPLIST_PATH}"`

echo "${version}"
echo "${build_num}"

old_version_path=./icon_version.txt
if [ ! -d $old_version_path ]; then
	touch $old_version_path
fi
old_version=`cat $old_version_path`
echo $old_version
if [[ $old_version == $version ]]; then
	echo "已添加过,不再重复添加"
	exit 0;
fi

date_now="$(date +"%Y.%m.%d")"
icon_path=${SRCROOT}/$TARGETNAME/Assets.xcassets/AppIcon.appiconset
copy_icon_path=./icon_copy
if [ ! -d $copy_icon_path ]; then
  cp -r $icon_path $copy_icon_path
fi

function read_dir() {
  for file in `ls $1`
    do
      if [ -d $1"/"$file ]
      then
        read_dir $1"/"$file
      else
        if [ "${file##*.}"x = "png"x ];then
          icon_width=`identify -format "%[fx:w]" $1"/"$file`
          echo $icon_width
          mark_width=$icon_width
          mark_hight=`expr $mark_width / 3`
          convert -background '#0005' -fill white -gravity center -size "${mark_width}x${mark_hight}" caption:"${version}\n${date_now}" $copy_icon_path"/"$file +swap -gravity south -composite $1"/"$file
          echo "处理图片${file}"
        fi
    fi
  done
}
read_dir $icon_path
echo $version > icon_version.txt

echo "=== end icon add version"

示例Demo

MIT License Copyright (c) 2021 ayangcool100 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

图标添加版本号 展开 收起
Objective-C
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化