Wednesday, 19 June 2013

Automagically versioning of iOS projects for a team using git

In our shop, we are building iOS projects as a team. We use git as our distributed version control system.

Display an automatic build number within the app, and have it updated properly across all developers.

We display the current build information inside a simple dialog using code like this:

NSDictionary *appInfo = [[NSBundle mainBundle] infoDictionary];
NSString *versionStr = [NSString stringWithFormat:@"%@ (Build %@)",
                                [appInfo objectForKey:@"CFBundleShortVersionString"],
                                [appInfo objectForKey:@"CFBundleVersion"]];
UILabel *versionLabel = [[UILabel alloc] initWithFrame:versionLabelFrame];
versionLabel.font = [[UIFont contentFont] fontWithSize:10.0];
versionLabel.text = [NSString stringWithFormat:@"Version: %@", versionStr];

Which gives us this nice output: Version: 1.0 (Build 311)

Making this happen can be as simple as inserting the proper value into the CFBundleVersion field of the apps' Info.plist file.

That task is pretty simple if you're working solo. With multiple members contributing however, it becomes tricky. Throw in the curve ball that is git's distributed versioning, and it gets really complicated.

Some online searching lead us to try following these very old articles.

They were successful in what they attempted, but their use cases are slightly different that ours. In those examples both authors are working on solo projects, and want to retain more control over the incrementing of the build numbers.

On our team, we want the build number to increase with every single commit to the repo. This is because each build is automatically extracted from git and pushed out to our internal testers using TestFlight. The users can accurately report to us issues based on a build number.

Handling a single version number across multiple developers using a distributed version control system.

Macros with the Jenkins Continuous Integration server

Jenkins CI logo

Configure Jenkins using the Xcode Plugin.
Jenkins uses environment variables to track and expose each build it does on our behalf. In this way, each build knows the current build number.

This plugins will call the avgtool to bump the current build number and then stick the result into the main target's Info.plist.

In our case, we use the brilliant, and affordable build service from Their build server already has the necessary plugins installed. For us, it was as simple as adding "${BUILD_NUMBER}" to the Technical Version field of the Xcode plugin.

Now the entire process is as easy as a git checkin. Every single time any of the developers on the team pushes a build to git, we get Jenkins to bump the build number, and inject that into Info.plist before building the project. (As a bonus, it runs our unit tests and proceeds or halts based on those results.)
Each successful build is then sent to TestFlight for distribution to the distribution list of our choosing: Developer, Internal or External testers. This last decision is made manually, as we don't want to flood our testing teams with several builds each day.

Wednesday, 12 June 2013

Early thoughts on iOS 7

I installed the first beta of iOS 7 on Monday night and have been playing around with it. Constantly. I have no choice really, it's installed on my personal, daily use iPhone.

These are my thoughts:
  • The new UI is gorgeous.
  • I love the extra, subtle animations throughout. Esepcially the fade in/fade out when sleeping/waking the device.
  • This build is a battery SUCK! Down to 77% battery from the time I wake in the morning, to getting on the bus to work. No doubt this will improve dramatically before too long.
  • Having apps update in the background is great! Yesterday I had 32 apps update during the day, so almost every time I glanced at my iPhone, I could see one or more apps being updated. Luckily, I never needed to use one while it was being updated. Rare, but I guess it could happen.
  • We finally have quick access to the common settings, including switching the radios on and off, as well as a handy flashlight(!) 
  • We can now share passes, and scan in new ones, right from within Passbook
All in all, I think I'm going to love iOS 7. I'm really looking forward to opening up the SDK, and playing with the internals. 

Designed by Apple in California

I tell you, I LOVE the culture of excellence they have baked into the core of this company! 

Here's the poem they opened their 2013 developer conference with. Who does this?!

Apple!!! Yaaaaayyyyyy!

This is it.
This is what matters.
How it makes someone feel.
When you start by imagining
What that might be like,
You step back.
You think.

Who will this help?
Will it make life better?
Does this deserve to exist?
If you are busy making everything,
How can you perfect anything?

We don't believe in coincidence.
Or dumb luck.
There are a thousand “no’s” 
For every “yes.”
We spend a lot of time
On a few great things.
Until every idea we touch
Enhances each life it touches.

We’re engineers and artists.
Craftsmen and inventors.
We sign our work.
You may rarely look at it.
But you'll always feel it.
This is our signature.
And it means everything.