My first app available on the app store…

A while ago now I decided that going through the tutorials on Objective C in a book was all very well but I really needed to write something of my own from scratch in order to really get to grips with it, and I wrote a version of the old Mastermind or Bulls and Cows game where you have to guess the secret code based on clues about how many of your guesses are correct and how many are in the code but in the wrong place. To make it more fun I made it against the clock, and added a scoring system where you are awarded points based on how quickly you got the answer, but with points taken away again for each guess to discourage just trying every combination. I also used numbers rather than colours and the picker wheel UI which is a standard GUI element in Cocoa Touch.

This simple game proved to be a good way to learn about quite a few aspects of development, such as the difference between regular arrays and mutable arrays, how timer objects work, how to store data in plists, how the settings bundle works, and so on.

Anyway, when you’re 90% finished you’re halfway there goes the old saying, so a couple of weeks ago I decided to finish off the app to a proper standard and get it published. In addition to obvious things like adding instructions and making an icon, there turned out to be several other things to learn such as obtaining another device profile from Apple to build against (I already had a profile for my iPod Touch so I could build and run my program on the device, but you need another profile again for distribution), all of which was quite time consuming and involved. A lot of the reason why it’s quite involved is to do with Apple’s decision to lock down iPhone OS so that the only way to install software (officially at least) is via Apple.

When everything was finished and built against the new distribution profile in XCode I submitted it to Apple and awaited their decision – there seems to be a degree of automated checking which happened straight away but once that was happy the status of my app was shown as ‘waiting for review’ After 24 hours this changed to ‘in review’, and then a day later it was approved – see it here on the App Store.

At this point I encountered a couple of new traps for the unwary – first, my app is showing as only available for OS 3.1 (which I have installed on my iPod Touch) even though I didn’t use any APIs that weren’t in 3.0, which probably reduces the possible number of customers by a large margin (my son for example doesn’t see why he would spend any of his pocket money on updating the OS on his Touch) so I need to find out how to remove that restriction. Secondly, the App Store is meant to display apps by release date as well as by best selling, which is the only way a new app will get any visibility to potential customers on the store. However this seems to be a bit confusing at best (some blogs say broken); for several days my app didn’t appear on this list at all, and then it appeared but a very long way down where it won’t be seen by many people. Apple don’t seem to be very clear on exactly how this works, and this is another thing that I’m glad I’ve found out about on my first app and not when I come to release something which I’d invested a lot of time in and needed a return from.

You can read more about ‘CodeSpin’ here and if you like that sort of puzzle game, why not give it a try? I’m hoping that the scoring system (it remembers your high score for all 4 skill levels) and the element of trying to beat the clock will make it quite addictive – my best score so far is 716, if you beat that let me know!

Getting started

So, how do you get into iPhone development then?

Well, the first step is to get a Mac, as the development kit is only available for Mac. I’d never owned a Mac, so that’s another new thing for me. Which is good.

So, I went off to the Apple Store in my local mega-mall (MeadowHell as it’s known around here) and bought a nice shiny white MacBook from one of the achingly keen people there. I’d only been in the Apple Store once before, to buy a power convertor for my iPod Touch so that it would charge in the car (thanks to Apple changing the voltage that newer iPods work on, something to do with USB versus Firewire, in other words 5v instead of 12v, guess what voltage car stereos work on), and for some reason the people there remind me of the Stepford Wives. Perhaps I just need to be assimilated…

The second thing I did was to buy a book.  After some intensive browsing in the bookshop I decided on “Beginning iPhone 3 Development” by Dave Mark and Jeff LaMarche, published by Apress. It seems fairly readable, full of worked examples, and has a website with a forum to go with it.

So I get home with my MacBook, switch it on, and first impressions are good – it powered up fast, found my home wifi, asked me for the WEP key, and that was it, all sorted. Everything looks nice, and once I got the hang of the new multi-touch track pad I was away.

So first task, download the iPhone SDK (software development kit). This is available free on Apple’s website, though you have to register. Although the development kit is free, if you want to actually run apps on your iPod/iPhone (or publish apps via the App Store) you have to pay $99 for an individual or $299 for a company. I left that step out for now, as you can run your code on the simulator which runs on the Mac and is part of the development kit.

The development kit consists of the following:

  • Xcode
  • Interface Builder
  • iPhone simulator

Xcode is the place where you build your code, and Interface Builder allows you to build the GUI to go with it. They’re nicely interlinked, Interface Builder automatically picking up on the parts of your code relating to GUI elements and allowing you to put things together quickly. iPhone simulator allows you to run your code and see the results on a simulated iPhone on your Mac, so you don’t need to port the code to your own iPhone until it all seems to be working properly in the simulator.

The next thing to note is that the language used is Objective-C. This is an extension to C, adding object-oriented concepts. The object oriented syntax is based on the Smalltalk language, and looked pretty odd to me, despite having done a little Smalltalk programming at university. The other object-oriented C like language I’ve had exposure to before is C++, and the syntax is quite different, though the concepts are the same. There are a lot of square brackets involved!

The other initial thing to note is that there is something called Cocoa Touch. This is the API for the operating system used on the iPhone / iPod Touch, and is similar to Cocoa on Mac OSX, or I guess .net or MFC in Windows. It’s basically an API in the form of a bunch of classes (in Objective C) that your programs will make use of to interact with the iPhone.

So, looks like there’ll be plenty to learn…!