As a Sparkled application, MPlayerX needs an automatic count-up mechanism between versions.
1. Count up git versions
Git doesn’t provide version number, it only gives out checksum of the commits, so let’s make one.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
|
You could download this piece of script here.
Please note that this script always count up commits in the remote branch origin/master and local, so change the 8th line if you want to work in other branches.
You could set an initial number if necessary, in the 15th line.
2. Modify the info.plist by the version number
At first I implemented by some dirty string matching scripts, it works but ugly. Then I found ScriptingBridge, thanks to it I could access the plist by ruby as I do by ObjC, this is much easier.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
|
This piece of script could be downloaded here.
3. Automate it
0. Put the two script files above into your project folder, and then open your project.
1. Add a new Aggregate Target, let’s say Update version in info.plist.
2. Inside of this target, add a Run Script build phase.
3. Add the following code into the shell area.
1 2 3 4 5 6 7 8 |
|
4. Then go back to your application target, add the dependency.
Notice
Remember to deploy your application always in the same branch, otherwise the number could be messed up, since the script only count up commits in origin/master and you current local branch.