方法一:
UPDATE 2:
This causes builds to be canceled! Have a look at S1LENT WARRIOR's answer below, it seems to be working better.
UPDATE 1:
In the latest version of Xcode (Version 11.1) you can do the build number auto increment fairly easily.
Here are the steps:
Go to your target's Build Settings
Search for Versioning System
Set it's value to Apple Generic
Go to your target's Build Phases
Add a new Run Script
Add the following line agvtool next-version -all
Do this for all your targets and their build numbers will all be synced and updated every time you run any of the targets.
方法二
In Info.plist, set:
CFBundleShortVersionString to $(MARKETING_VERSION)
CFBundleVersion to $(CURRENT_PROJECT_VERSION)
In target build settings:
set Versioning System to "Apple Generic"
set Current Project Version to 1 (or whatever version you want)
set Marketing Version to 1.0.0 (or whatever version you want)
In the scheme > Archive:
add a post-action "Run Script Action":
Provide build settings from: your app
in the script: cd ${PROJECT_DIR} ; xcrun agvtool next-version -all ;
方法三
Just change CFBundleVersion from $(CURRENT_PROJECT_VERSION) to number, in my case is 1000 in Info.plist
<key>CFBundleVersion</key>
<string>1004</string>