iOS 之版本号 Version / Build 分析与脚本自动化

概念:

Version:在plist文件中的key是“CFBundleShortVersionString”,和AppStore上的版本号保持一致;

Build:在plist中的key是“CFBundleVersion”,代表build的版本号,该值每次build之后都应该增加1;


格式:

Version: 程序版本号{主版本号.次版本号.维护号}

Build: 编译次数统计


代码获取:

Verison号:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
或
[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleShortVersionString"];

Build号:

[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion”];


脚本控制Build版本号自加1:


步骤:

双击xcode project, 打开项目;

在Xcode左栏, 选中项目;

在Xcode中栏偏左, 选中TARGETS->${项目名称};

在Xcode中栏偏上, 选中Build Phases;

在Xcode中栏左上角, 选中+号, 再选择New Run Script Build Phases;



在新出现的Run Script栏中, 于Shell输入框中输入如下脚本:

#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=$(($buildNumber + 1))
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"




Build Project, 检查Build版本号自加1, 即设置成功.



发布了71 篇原创文章 · 获赞 51 · 访问量 26万+

猜你喜欢

转载自blog.csdn.net/mapboo/article/details/49247037