XCODE 中Version 和 Build的區(qū)別

from: https://stackoverflow.com/questions/6851660/version-vs-build-in-xcode

Apple sort of rearranged/repurposed the fields.

Going forward, if you look on the Info tab for your Application Target, you should use the "Bundle versions string, short" as your Version (e.g., 3.4.0) and "Bundle version" as your Build (e.g., 500 or 1A500). If you don't see them both, you can add them. Those will map to the proper Version and Build textboxes on the Summary tab; they are the same values.

When viewing the Info tab, if you right-click and selectShow Raw Keys/Values, you'll see the actual names areCFBundleShortVersionString(Version) andCFBundleVersion(Build).

The Version is usually used how you appear to have been using it with Xcode 3. I'm not sure on what level you're asking about the Version/Build difference, so I'll answer it philosophically.

There are all sorts of schemes, but a popular one is:

{MajorVersion}.{MinorVersion}.{Revision}

Major version- Major changes, redesigns, and functionality changes

Minor version- Minor improvements, additions to functionality

Revision- A patch number for bug-fixes

Then the Build is used separately to indicate the total number of builds for a release or for the entire product lifetime.

Many developers start the Build number at 0, and every time they build they increase the number by one, increasing forever. In my projects, I have a script that automatically increases the build number every time I build. See instructions for that below.

Release 1.0.0 might be build 542. It took 542 builds to get to a 1.0.0 release.

Release 1.0.1 might be build 578.

Release 1.1.0 might be build 694.

Release 2.0.0 might be build 949.

Other developers, including Apple, have a Build number comprised of a major version + minor version + number of builds for the release. These are the actual software version numbers, as opposed to the values used for marketing.

If you go toXcodemenu >About Xcode, you'll see the Version and Build numbers. If you hit theMore Info...button you'll see a bunch of different versions. Since theMore Info...button was removed in Xcode 5, this information is also available from theSoftware > Developersection of theSystem Informationapp, available by openingApplemenu >About This Mac>System Report....

For example, Xcode 4.2 (4C139). Marketing version 4.2 is Build major version 4, Build minor version C, and Build number 139. The next release (presumably 4.3) will likely be Build release 4D, and the Build number will start over at 0 and increment from there.

The iPhone Simulator Version/Build numbers are the same way, as are iPhones, Macs, etc.

3.2: (7W367a)

4.0: (8A400)

4.1: (8B117)

4.2: (8C134)

4.3: (8H7)

Update: By request, here are the steps to create a script that runs each time you build your app in Xcode to read the Build number, increment it, and write it back to the app's{App}-Info.plistfile. There are optional, additional steps if you want to write your version/build numbers to yourSettings.bundle/Root*.plistfile(s).

This is extended from the how-to articlehere.

In Xcode 4.2 - 5.0:

Load your Xcode project.

In the left hand pane, click on your project at the very top of the hierarchy. This will load the project settings editor.

On the left-hand side of the center window pane, click on your app under theTARGETSheading. You will need to configure this setup for each project target.

Select theBuild Phasestab.

In Xcode 4, at the bottom right, click theAdd Build Phasebutton and selectAdd Run Script.

In Xcode 5, selectEditormenu >Add Build Phase>Add Run Script Build Phase.

Drag-and-drop the newRun Scriptphase to move it to just before theCopy Bundle Resourcesphase (when the app-info.plist file will be bundled with your app).

In the newRun Scriptphase, setShell:/bin/bash.

Copy and paste the following into the script area for integer build numbers:

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

As @Bdebeez pointed out, theApple Generic Versioning Tool(agvtool) is also available. If you prefer to use it instead, then there are a couple things to change first:

Select theBuild Settingstab.

Under theVersioningsection, set theCurrent Project Versionto the initial build number you want to use, e.g.,1.

Back on theBuild Phasestab, drag-and-drop yourRun Scriptphase after theCopy Bundle Resourcesphase to avoid a race condition when trying to both build and update the source file that includes your build number.

Note that with theagvtoolmethod you may still periodically get failed/canceled builds with no errors. For this reason, I don't recommend usingagvtoolwith this script.

Nevertheless, in yourRun Scriptphase, you can use the following script:

"${DEVELOPER_BIN_DIR}/agvtool"next-version-all

Thenext-versionargument increments the build number (bumpis also an alias for the same thing), and-allupdatesInfo.plistwith the new build number.

And if you have a Settings bundle where you show the Version and Build, you can add the following to the end of the script to update the version and build.Note: Change thePreferenceSpecifiersvalues to match your settings.PreferenceSpecifiers:2means look at the item at index 2 under thePreferenceSpecifiersarray in your plist file, so for a 0-based index, that's the 3rd preference setting in the array.

productVersion=$(/usr/libexec/PlistBuddy-c"Print CFBundleShortVersionString""$INFOPLIST_FILE")/usr/libexec/PlistBuddy-c"Set PreferenceSpecifiers:2:DefaultValue $buildNumber"Settings.bundle/Root.plist/usr/libexec/PlistBuddy-c"Set PreferenceSpecifiers:1:DefaultValue $productVersion"Settings.bundle/Root.plist

If you're usingagvtoolinstead of reading theInfo.plistdirectly, you can add the following to your script instead:

buildNumber=$("${DEVELOPER_BIN_DIR}/agvtool"what-version-terse)productVersion=$("${DEVELOPER_BIN_DIR}/agvtool"what-marketing-version-terse1)/usr/libexec/PlistBuddy-c"Set PreferenceSpecifiers:2:DefaultValue $buildNumber"Settings.bundle/Root.plist/usr/libexec/PlistBuddy-c"Set PreferenceSpecifiers:1:DefaultValue $productVersion"Settings.bundle/Root.plist

And if you have a universal app for iPad & iPhone, then you can also set the settings for the iPhone file:

/usr/libexec/PlistBuddy-c"Set PreferenceSpecifiers:2:DefaultValue $buildNumber"Settings.bundle/Root~iphone.plist/usr/libexec/PlistBuddy-c"Set PreferenceSpecifiers:1:DefaultValue $productVersion"Settings.bundle/Root~iphone.plist

最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
  • 序言:七十年代末承二,一起剝皮案震驚了整個濱河市蔚叨,隨后出現的幾起案子舀瓢,更是在濱河造成了極大的恐慌匾寝,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件骡和,死亡現場離奇詭異抚笔,居然都是意外死亡衷戈,警方通過查閱死者的電腦和手機,發(fā)現死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門稠通,熙熙樓的掌柜王于貴愁眉苦臉地迎上來衬衬,“玉大人,你說我怎么就攤上這事改橘∽涛荆” “怎么了?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵飞主,是天一觀的道長狮惜。 經常有香客問我,道長碌识,這世上最難降的妖魔是什么碾篡? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮丸冕,結果婚禮上耽梅,老公的妹妹穿的比我還像新娘。我一直安慰自己胖烛,他們只是感情好眼姐,可當我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布诅迷。 她就那樣靜靜地躺著,像睡著了一般众旗。 火紅的嫁衣襯著肌膚如雪罢杉。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天贡歧,我揣著相機與錄音滩租,去河邊找鬼。 笑死利朵,一個胖子當著我的面吹牛律想,可吹牛的內容都是我干的。 我是一名探鬼主播绍弟,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼技即,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了樟遣?” 一聲冷哼從身側響起而叼,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤,失蹤者是張志新(化名)和其女友劉穎豹悬,沒想到半個月后葵陵,有當地人在樹林里發(fā)現了一具尸體,經...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡瞻佛,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年脱篙,在試婚紗的時候發(fā)現自己被綠了。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片涤久。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡涡尘,死狀恐怖,靈堂內的尸體忽然破棺而出响迂,到底是詐尸還是另有隱情考抄,我是刑警寧澤,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布蔗彤,位于F島的核電站川梅,受9級特大地震影響,放射性物質發(fā)生泄漏然遏。R本人自食惡果不足惜贫途,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望待侵。 院中可真熱鬧丢早,春花似錦、人聲如沸。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽。三九已至农猬,卻和暖如春赡艰,著一層夾襖步出監(jiān)牢的瞬間,已是汗流浹背斤葱。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工慷垮, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留,地道東北人揍堕。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓料身,卻偏偏與公主長得像,于是被迫代替她去往敵國和親鹤啡。 傳聞我的和親對象是個殘疾皇子惯驼,可洞房花燭夜當晚...
    茶點故事閱讀 44,592評論 2 353

推薦閱讀更多精彩內容