This article is more than 1 year old

How I wrote an iPhone application

An introduction to the world of mobile Web 2.0

If an El Reg hack can write an iPhone application then anyone can, so we thought we'd have a go and pass on our experience in the hope that others can build something more useful.

In proper Web 2.0 fashion we decided to create an application which would achieve nothing and have no commercial potential. Therefore, our application would load The Register website and parse its contents to remove all references to the ubiquitous iPhone, replacing the term with a string of the user's choice.

First thing was to download the iPhone documentation from the Apple Developer Connection, which required us to sign up with a valid email address and left us with a small pile of pdf documents to read.

Unfortunately, these documents proved almost entirely useless as they talked at length about the style and usability of iPhone applications, but said very little about how to write them. The JavaScript guides were a bit more useful, but not a lot, and we got more mileage out of our rather elderly "JavaScript Definitive Guide" (circa 1997) and various JavaScript websites.

We also needed to download the latest version of Safari - you're supposed to be able to develop using Safari then deploy straight onto an iPhone, though life is not really that simple, and that does need XP or Vista (or a nice Mac, but our budget wouldn't stretch).

Assuming one isn't going down the native-applications-for-unlocked-iPhones-only route, then iPhone applications are written in JavaScript - an annoying scripting language with aspirations of objecthood and no significant relationship to Java. JavaScripts can't live alone - they are embedded in web pages - but as we wanted our app to load other web pages we made that page a frameset (which can contain other pages).

All our development was done using PFE - we eschewed more complex environments for what should be a bit of quick text editing.

Initially, our frameset only contained a single frame, to load the El Reg pages into, but we had to add a second frame when it became clear that the iPhone's "back" button wasn't going to operate as we would have liked. But even with the second frame for the menu bar our HTML page managed to keep it simple:

<HTML>
  <HEAD>
    <TITLE>Test using frames</TITLE>
    //JavaScript goes here
  </HEAD>
  <FRAMESET ROWS="*,32" FRAMEBORDER="no" onLoad="startUp();">
    <FRAME SRC="blank1.html" NAME="left">
    <FRAME SRC="menubar.html" name="menu">
  </FRAMESET>
</HTML>

Then it was just a matter of inserting our script into the header with a function called "startUp" to be run when the page had loaded, the script is listed in its entirety at the end of this article. blank1.html is just a holding text, while menubar.html contains our additional back button and an option to change the replacement text.

More about

More about

More about

TIP US OFF

Send us news


Other stories you might like