国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

在iOSApp的圖標上顯示版本信息

2019-11-14 19:51:56
字體:
來源:轉載
供稿:網友

最近讀到一篇文章(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中的所有信息:

Shell代碼 復制代碼 收藏代碼
  1. version = `/usr/libexec/PlistBuddy -c ""騷窩對對碰-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安裝什么都很方便:

Shell代碼 復制代碼 收藏代碼
  1. brew install imagemagick  
  2. brew install ghostscript  
brew install imagemagickbrew install ghostscript

安裝好后,通過ImageMagicK的convert功能把文字寫到圖片上,示例:在Icon.png上,創建一個背景色為‘#0008’的,長144,高40的矩形,然后用白色字體把把“test master 56789998”居中寫到矩形中。

Shell代碼 復制代碼 收藏代碼
  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中:

Shell代碼 復制代碼 收藏代碼
  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.   
  5. function processIcon() {  
  6.     export PATH=$PATH:/usr/local/bin  
  7.     base_file=$1  
  8.     base_path=`find ${SRCROOT} -name $base_file`  
  9.   
  10.     if [[ ! -f ${base_path} || -z ${base_path} ]]; then  
  11.         return;  
  12.     fi  
  13.   
  14.     target_file=`echo $base_file | sed "s/_base//"`  
  15.     target_path="${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}"  
  16.   
  17.     if [ $CONFIGURATION = "Release" ]; then  
  18.     cp ${base_file} $target_path  
  19.     return  
  20.     fi  
  21.   
  22.     width=`identify -format %w ${base_path}`  
  23.   
  24.     convert -background '#0008' -fill white -gravity center -size ${width}x40/  
  25.     caption:"${version} ${branch} ${commit}"/  
  26.     ${base_path} +swap -gravity south -composite ${target_path}  
  27. }  
  28.   
  29. processIcon "Icon_base.png"  
  30. processIcon "Icon@2x_base.png"  
  31. processIcon "Icon-72_base.png"  
  32. 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上得到的效果:  


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 乌恰县| 尉氏县| 邢台县| 修水县| 嘉黎县| 梓潼县| 大姚县| 涿鹿县| 阜新市| 衡南县| 林口县| 赤壁市| 宁明县| 汉川市| 吉安市| 彩票| 新化县| 古丈县| 平安县| 平和县| 莫力| 梁山县| 额敏县| 阳谷县| 新田县| 安阳市| 昌乐县| 涡阳县| 浠水县| 新泰市| 扬州市| 饶阳县| 华阴市| 河间市| 醴陵市| 澎湖县| 沁源县| 康平县| 永泰县| 大石桥市| 彰武县|