我有一个用Xcode 3开发的应用程序,最近开始用Xcode 4编辑。在目标摘要中,我有带有字段的iOS应用程序目标表单:标识符、版本、构建、设备和部署目标。版本字段是空白的,构建字段是3.4.0(这与我仍然使用Xcode 3编辑应用程序时的版本相匹配)。
我的问题是:
版本和构建字段之间的区别是什么? 为什么我升级到Xcode 4后版本字段是空的?
我有一个用Xcode 3开发的应用程序,最近开始用Xcode 4编辑。在目标摘要中,我有带有字段的iOS应用程序目标表单:标识符、版本、构建、设备和部署目标。版本字段是空白的,构建字段是3.4.0(这与我仍然使用Xcode 3编辑应用程序时的版本相匹配)。
我的问题是:
版本和构建字段之间的区别是什么? 为什么我升级到Xcode 4后版本字段是空的?
当前回答
Build号是一个内部编号,表示应用程序的当前状态。它与版本号不同,因为它通常不是面向用户的,也不像版本号通常会表示任何差异/功能/升级。
你可以这样想:
Build (CFBundleVersion): The number of the build. Usually you start this at 1 and increase by 1 with each build of the app. It quickly allows for comparisons of which build is more recent and it denotes the sense of progress of the codebase. These can be overwhelmingly valuable when working with QA and needing to be sure bugs are logged against the right builds. Marketing Version (CFBundleShortVersionString): The user-facing number you are using to denote this version of your app. Usually this follows a Major.minor version scheme (e.g. MyAwesomeApp 1.2) to let users know which releases are smaller maintenance updates and which are big deal new features.
To use this effectively in your projects, Apple provides a great tool called agvtool. I highly recommend using this as it is MUCH more simple than scripting up plist changes. It allows you to easily set both the build number and the marketing version. It is particularly useful when scripting (for instance, easily updating the build number on each build or even querying what the current build number is). It can even do more exotic things like tag your SVN for you when you update the build number.
使用它:
在Xcode中,在版本控制下,设置你的项目使用“Apple Generic”。 在终端 agvtool新版本1(将Build号设置为1) agvtool new-marketing-version 1.0(将Marketing版本设置为1.0)
请参阅agvtool的手册页,以获得大量有用的信息
其他回答
Build号是一个内部编号,表示应用程序的当前状态。它与版本号不同,因为它通常不是面向用户的,也不像版本号通常会表示任何差异/功能/升级。
你可以这样想:
Build (CFBundleVersion): The number of the build. Usually you start this at 1 and increase by 1 with each build of the app. It quickly allows for comparisons of which build is more recent and it denotes the sense of progress of the codebase. These can be overwhelmingly valuable when working with QA and needing to be sure bugs are logged against the right builds. Marketing Version (CFBundleShortVersionString): The user-facing number you are using to denote this version of your app. Usually this follows a Major.minor version scheme (e.g. MyAwesomeApp 1.2) to let users know which releases are smaller maintenance updates and which are big deal new features.
To use this effectively in your projects, Apple provides a great tool called agvtool. I highly recommend using this as it is MUCH more simple than scripting up plist changes. It allows you to easily set both the build number and the marketing version. It is particularly useful when scripting (for instance, easily updating the build number on each build or even querying what the current build number is). It can even do more exotic things like tag your SVN for you when you update the build number.
使用它:
在Xcode中,在版本控制下,设置你的项目使用“Apple Generic”。 在终端 agvtool新版本1(将Build号设置为1) agvtool new-marketing-version 1.0(将Marketing版本设置为1.0)
请参阅agvtool的手册页,以获得大量有用的信息
感谢@nekno和@ale84的精彩回答。
但是,我修改了@ale84的脚本,它很少增加浮点的构建号。
incl的值可以根据您的浮动格式要求进行更改。 例如:如果incl = .01,输出格式为 ... 1.19, 1.20, 1.21 ...
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
incl=.01
buildNumber=`echo $buildNumber + $incl|bc`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
如果构建号是浮点值,那么上面答案中自动递增构建号的脚本对我不起作用,所以我稍微修改了一下:
#!/bin/bash
buildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$INFOPLIST_FILE")
buildNumber=`echo $buildNumber +1|bc`
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $buildNumber" "$INFOPLIST_FILE"
我在Xcode 14.2上,并将以下bash脚本添加到项目包中的.sh文件中。然后我使用一个运行脚本构建阶段来调用这个脚本。当我存档项目时,版本和包更新了几次,但随后停止了增量。关于为什么脚本不会继续增加有任何反馈吗?感谢反馈。
currentVersionString=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$PROJECT_DIR/SupportingFiles/$INFOPLIST_FILE")
currentBuildNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleVersion" "$PROJECT_DIR/SupportingFiles/$INFOPLIST_FILE")
newBuildNumber=$((currentBuildNumber + 1))
IFS='.' read -ra version <<< "$currentVersionString"
version[2]=$((version[2] + 1))
newVersionString="${version[0]}.${version[1]}.${version[2]}"
/usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $newVersionString" "$PROJECT_DIR/SupportingFiles/$INFOPLIST_FILE"
/usr/libexec/PlistBuddy -c "Set :CFBundleVersion $newBuildNumber" "$PROJECT_DIR/SupportingFiles/$INFOPLIST_FILE"
另一种方法是在appDelegate didFinishLaunchingWithOptions中设置版本号:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSString * ver = [self myVersion];
NSLog(@"version: %@",ver);
NSUserDefaults* userDefaults = [NSUserDefaults standardUserDefaults];
[userDefaults setObject:ver forKey:@"version"];
return YES;
}
- (NSString *) myVersion {
NSString *version = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"];
NSString *build = [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
return [NSString stringWithFormat:@"%@ build %@", version, build];
}