最近读到一篇文章(http://www.merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/)介绍了一种非常简单的,把版本信息显示到iOS app的icon上的方式, 有了这个技能,在测试多版本的时候,测试人员可以直接从icon上看到当前测试的版本,无需在到HockeyApp或者TestFlight中去看哪些机器使用的哪个版本,可以提升效率。
下面是我如何Get这个技能的:
首先,获取想展示到图标上的信息,在我的app中,我想展示version,branch,commit信息,即当前测试的App是哪个分支上得哪个版本,在哪次提交之后build的. 这些信息最后是通过shell脚本弄上去的,因此,只要shell脚本能读取到这些信息就成。对于iOS App来说,Version信息来源于项目的.plist文件,在Mac上提供了PlistBuddy工具来帮助开发者提取plist中的所有信息:

  1. version = `/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "骚窝对对碰-info.plist"`  #1.0
version = `/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "骚窝对对碰-info.plist"`  #1.0

至于branch和commit信息则是根据Version control工具来定的,我使用的是git:

  1. branch=`git rev-parse --abbrev-ref HEAD`
  2. commit=`git rev-parse --short HEAD`
branch=`git rev-parse --abbrev-ref HEAD`
commit=`git rev-parse --short HEAD`

接着,有了想写到icon的信息,接下来是如何写到icon上,这儿的工具是ImageMagick和ghostscript,ImageMagick为在命令行下操作图片提供了很多的功能,而ghostscript则是为了在icon上写的字体好看一点。在Mac下有了homebrew安装什么都很方便:

  1. brew install imagemagick
  2. brew install ghostscript
brew install imagemagick
brew install ghostscript

安装好后,通过ImageMagicK的convert功能把文字写到图片上,示例:在Icon.png上,创建一个背景色为‘#0008’的,长144,高40的矩形,然后用白色字体把把“test master 56789998”居中写到矩形中。

  1. convert -background '#0008' -fill white -gravity center -size 144x40    caption:"test master 56789998"   ./Icon.png  +swap -gravity south -composite ./convert.png
convert -background '#0008' -fill white -gravity center -size 144x40    caption:"test master 56789998"   ./Icon.png  +swap -gravity south -composite ./convert.png

转换后的前后对比如下:
最后,有了要写的信息和如何写的方式,接下来,就是在Xcode中完成配置,把该功能加入到iOS App的构建过程中。
1.把所有的Icon文件改为*_base.png, 因为最后的Icon文件是由脚本生成,因此需把当前Icon改名以防冲突。 2.在Target的Build Phases中添加一个Run Script的Build Phase, 怎么做:http://www.runscriptbuildphase.com/ 3.把前面的图片处理过程,添加到Run Script中:

  1. commit=`git rev-parse --short HEAD`
  2. branch=`git rev-parse --abbrev-ref HEAD`
  3. version=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"`
  4. function processIcon() {
  5. export PATH=$PATH:/usr/local/bin
  6. base_file=$1
  7. base_path=`find ${SRCROOT} -name $base_file`
  8. if [[ ! -f ${base_path} || -z ${base_path} ]]; then
  9. return;
  10. fi
  11. target_file=`echo $base_file | sed "s/_base//"`
  12. target_path="${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}"
  13. if [ $CONFIGURATION = "Release" ]; then
  14. cp ${base_file} $target_path
  15. return
  16. fi
  17. width=`identify -format %w ${base_path}`
  18. convert -background '#0008' -fill white -gravity center -size ${width}x40\
  19. caption:"${version} ${branch} ${commit}"\
  20. ${base_path} +swap -gravity south -composite ${target_path}
  21. }
  22. processIcon "Icon_base.png"
  23. processIcon "Icon@2x_base.png"
  24. processIcon "Icon-72_base.png"
  25. processIcon "Icon-72@2x_base.png"
commit=`git rev-parse --short HEAD`
branch=`git rev-parse --abbrev-ref HEAD`
version=`/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "${INFOPLIST_FILE}"` function processIcon() {
export PATH=$PATH:/usr/local/bin
base_file=$1
base_path=`find ${SRCROOT} -name $base_file` if [[ ! -f ${base_path} || -z ${base_path} ]]; then
return;
fi target_file=`echo $base_file | sed "s/_base//"`
target_path="${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}" if [ $CONFIGURATION = "Release" ]; then
cp ${base_file} $target_path
return
fi width=`identify -format %w ${base_path}` convert -background '#0008' -fill white -gravity center -size ${width}x40\
caption:"${version} ${branch} ${commit}"\
${base_path} +swap -gravity south -composite ${target_path}
} processIcon "Icon_base.png"
processIcon "Icon@2x_base.png"
processIcon "Icon-72_base.png"
processIcon "Icon-72@2x_base.png"

最后,在我的Simiulatro上得到的效果:

在iOS App的图标上显示版本信息的更多相关文章

  1. iOS开发——应用图标上显示消息数量

    iOS8以前: UIApplication *app = [UIApplication sharedApplication]; app.applicationIconBadgeNumber = num ...

  2. Linux显示版本信息并退出

    Linux显示版本信息并退出 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ cat --version cat (GNU coreutils) 8.21 Co ...

  3. 谈谈iOS app的线上性能监测

    在移动端开发者中最重要的KPI应该是崩溃率.当崩溃率稳定下来后,工作的重心就应该转移到性能优化上.那么问题来了,如果你的项目也没有接入任何性能监测SDK,没有量化的指标来衡量,那你说你优化了性能领导信 ...

  4. iOS 真机上图标不显示

    今天在调试时发现模拟器上图标显示了.但真机上测试时发现图标不显示. 解决办法 57*57  的图标然后命名为: Icon.png 这样显示就正常了. 参考资料:http://www.cnblogs.c ...

  5. 整合Settings.bundle显示版本信息

    本文转载至 http://www.cocoachina.com/ios/20141103/10112.html iOS开发XCode版本管理Debug开发Tips   现在你有一个App,你同事的iP ...

  6. PHP版本替换, phpinfo和php -v显示版本信息不一致

    环境:OS X EI Capitan 10.11 & lnmp 背景: 1想将lamp(xampp安装的,php5.2)换成 lnmp(php7.0)   2php5.2卸载(xampp卸载& ...

  7. Sharepoint2013:在页面上显示错误信息

    在sharepoint2013中我们需要修改以下三处的web.config,以显示错误信息 1, C:\inetpub\wwwroot\wss\VirtualDirectories\端口号\web.c ...

  8. iOS App启动图不显示的解决办法.

    1. 正常来说,启动图以及App图标需按照命名规则命名, 但是命名不规范并不影响显示; 2. 设置启动图的两种方法:      (1) iOS 8—xcode 6 之后新出LaunchScreen.s ...

  9. 在iOS APP中使用H5显示百度地图时如何支持HTTPS?

    现象: 公司正在开发一个iOSAPP,使用h5显示百度地图,但是发现同样的H5页面,在安卓可以显示出来,在iOS中就显示不出来. 原因分析: 但是现在iOS开发中,苹果已经要求在APP中的所有对外连接 ...

随机推荐

  1. javascript跨域请求RESTful Web Service

    跨域请求RESTful Web Service 当我们用js请求RESTful Web Service的时候,通常会出现跨域无法访问的问题,也就是无法正常得到我们要的值.jsonp是个解决问题的方法. ...

  2. hdu-5680 zxa and set(水题)

    题目链接: zxa and set Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Other ...

  3. While reading xxx.png pngcrush caught libpng error: Not a PNG file..

    While reading /XXX/XXX/XXX/img1.png pngcrush caught libpng error: Not a PNG filCould not find file: ...

  4. AspNetPager学习使用1

    今天开始研究使用AspNetPager 首先贴上下载链接:http://www.webdiyer.com/aspnetpager/downloads/ 在下载链接中,作者已经提供了使用方法.在这里,本 ...

  5. OS X 10.10 apache配置

    配置内容转自:http://www.linuxidc.com/Linux/2015-04/116347.htm 一.apache的配置 apache已经自带了,只需如下三个命令就可以了. 开启apac ...

  6. Table of Contents - Lombok

    Installation Lombok Annotations @Getter, @Setter, @ToString, @EqualsAndHashCode & @Data @NoArgsC ...

  7. vs2013发布时: sgen.exe 已退出 代码为 1

    出现这个错的时候,有查网上的.自己也亲试了一下,注意两个地方就行. 红色框里设成这样的值就OK了!

  8. 配置JDK和TOMCAT

    配置JDK 1.先从官网下载最新的JDK安装包,然后安装.安装过程中会询问是否再装JRE,因为JDK中已经包含JRE,所以不必重复安装. 2.注意安装的路径名最好不要有中文或者空格出现. 3.在系统环 ...

  9. CSS之简单树形菜单

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. hexo资源--theme等

    Hexo (https://github.com/hexojs/hexo) [3]hexo你的博客(http://ibruce.info/2013/11/22/hexo-your-blog/) [4] ...