Wednesday, January 09, 2008

Developing for the iPod Touch

Since the reason I got an iPod Touch was to develop applications for it, I though that it was about time I actually got round to giving it a go. This is a brief round-up of the tutorials I used, presented in the order I should have done them.

First step was to jailbreak the iPod to allow access to its file system. As I had OS v.1.1.2 this meant downgrading to 1.1.1. The instructions on this page worked perfectly for me. The longest part was downloading the two versions of the firmware from Apple.

When you run the Java .jar file in the last stage I recommend ticking the box to install SSH. Then, to connect to your iPod, first get its IP address from Settings -> Wifi and click on the arrow in the blue circle next to your active connection. Now from the Terminal, type:

ssh root@IPADDRESS


The default root password should be alpine, although you can easily change this using the SSH icon on the iPod. To begin with SSH is rather sparse since there are no command line tools installed. These can be found in the "BSD sub-system" package in the installer. Note, however, that I'm not sure whether installing them caused me the problems in the stage (and they can't be easily removed), but all things considered you're better off with them.

Next, in order to compile the toolchain used to build iPod apps, we need a copy of the iPod's file system. In theory we should be able to get this by using the scp command, thus:

sudo scp -r root@IPADDRESS:/ /usr/local/share/iphone-filesystem


Which should copy every file into the directory on your Mac where the toolchain Makefile expects it. However, for me this ran fine for 15 minutes and then stalled on "Resource Busy" / "not a regular file" errors for file in the /dev directory. Copying individual directories from route (/usr is the really important one) side-stepped this. Oh, and you may want to remove all your songs and movies from the iPod before you do this and save yourself a few hours.

Instructions for getting and compiling the toolchain can be found here, and with the preparation above should work without problems. To test that everything is working I used this Hello World source code, found via here. Download it (it should unzip automatically), then in the terminal navigate to the directory and run make. If everything is set up correctly you'll now have a file called "Hello" (identified as a UNIX executable by the Finder). Copy this to your iPod with:

scp ./Hello root@IPADDRESS:/Applications/


To run it, SSH into the iPod, navigate to the Applications folder, and run "Hello":

cd /Applications
./Hello


"Hello World" should be displayed on the iPod (wake it up and unlock it). You'll notice that the home button doesn't do anything. To kill the program, go back to SSH in the terminal and hit ctrl+C. The # prompt will reappear in the console and the iPod will drop back to the launch screen.

Well, that's it for compiling and running a first iPod app, now it's off to find some documentation for the iPod version of Cocoa.

No comments: