Automating Version Number for iOS / Mac Apps
UPDATE: format like
1.0.82 (E3B8), which makes perfect sense in alpha test stage since we wouldn’t want too many tags for alpha builds, is not accepted by
Apple anymore. We’ll have to use the
1.0.82 part only.
IMPORTANT: I’m still trying to figure out the best practice of this topic, thus the approach I described in this article may not be final.
Long story short:
Build Phases(Editor -> Add Build Phase), and put it before
Copy Bundle Resourcesso that we can increase version number in info.plist, and then copy plist into app bundle.
Add script as below. The magic here is
git rev-list HEAD | wc -l | tr -d ' 'that gives you the subversion-style revision number, which means if you’re not in master branch this doesn’t make any sense (that’s why I said I’m still figuring it out). Basically I don’t mind change version number in debug mode but you may want to uncomment the 2nd line if you stay in develop branch most of the time.
- Display version number somewhere in your UI.
– swift version –
The thing I’m not sure is that although
1.0.82 seems to be nice to non-tech person, it is not as good as git hash if you want to debug something. So maybe something like
1.0.82 (5cb5ec) would be better; anyway it’s very easy to modify the script in step 2 to make whatever version string you want.
Tags: Objective C Swift Xcode