TweetFollow Us on Twitter

Developing for the iPhone

Volume Number: 23 (2007)
Issue Number: 08
Column Tag: iPhone

Developing for the iPhone

OR: how I learned to stop worrying and love Web 2.0

by Marc S. Ressl

Introduction

The iPhone has finally come to us. After several months of speculation, jokes, disappointments and surprises, the incredible device hit the streets. In this article we will talk a little bit about the recent developments in the iPhone scene, about the kind of applications you can write for the iPhone, and about the ways you can implement them. We'll also discuss some human interface aspects, so you can start writing intuitive applications that "just work".

The missing software development kit

Let's talk a little bit about history. It was January 9th, 2007, a beautiful Tuesday morning at the MacWorld conference in San Francisco when Steve Jobs introduced the "next big thing", the iPhone.

During the following months the hype and spin grew to epic proportions. Rumor had it that the iPhone would be capable of some sort of third-party application development.

But in June, at Apple's developer conference WWDC 2007, the unexpected happened. Based on the fact that the full Safari engine is inside the phone, Steve Jobs introduced a "very sweet solution" for developing apps. Web 2.0 applications can look and behave exactly like iPhone applications, he claimed.

Most people weren't expecting a full-blown SDK in a version 1.0 device. However, his announcement let down some developers, as Jobs was hardly telling anything new. This feeling was only exacerbated by Jobs' claims from a week before, when he said that "...you can't do that stuff in a browser", while discussing the iPhone's internal Google Maps client.

In spite of Apple's real reasons for not opening up the iPhone (yet), there are many advantages with web applications:

· Security. Keeping third-party web applications sand-boxed in Safari protects the device and networks from software pathogens. The https protocol provides secure communications over the Internet. A stolen iPhone is no security concern, as no sensitive application data is stored locally. There is also no need for an application certificate, as with Symbian.

· Installations. No installation is needed, as an application just exists as a URL, a username and a password. As a side-effect, applications get copy protection. Your code stays on the server.

· Updates. Web-apps only need to be updated on the server. Update once, update everywhere.

· Access. Being platform-agnostic, a web-app for the iPhone works on a regular web browser and on other mobile browsers as well, wherever you are.

· Usability. HTML controls, enhanced with JavaScript, provide all the flexibility you could expect from a traditional application. Besides, the pinch gesture always works as expected.

· New ways for earning revenue. You can charge for usage of your app. Another possibility is to add advertisements to it.

· Efficient data transmission. There has been some criticism that web-apps would have a large overhead. But Safari has a cache, and Web 2.0 apps can be highly optimized.

Of course, the list of disadvantages is also quite long:

· Web applications can't be stored on the local file system, they are not available offline. Forget widgets à la Mac OS X.

· No access to the iPhone's resources. No direct sound playback or recording, no direct access to the camera, no interfacing with Bluetooth, no direct access to the Internet, no direct access to the cellular network, no direct access to iPhone's sensors.

· Computationally intensive tasks are not possible. No sound, image or video processing.

· Limited access to the multi-touch interface.

· Containment. Since web-apps are contained in Safari, they cannot call your attention while Safari is out of focus.

· No direct links to the applications from the iPhone home screen. If you want to open an application you have to open a Safari bookmark, and this is odd.

· Bills. Data service bills might get pretty hefty when roaming.

· This is not confirmed at the time of this writing, but there appears to be no access to the data on the local file system.

I want to write an application for the iPhone

Want to write an app for the iPhone? You should ask yourself first if it is feasible.

It should be feasible if your requirements are not on the list of disadvantages we just mentioned. Particularly well suited are applications that demand permanent connection, like instant messengers, remote control or directory look-up services. Group collaboration tools, regular office applications, calculators, converters, RSS readers, news tickers, and mobile mini-games are also good candidates.

But sadly there are many things that can't be implemented: Skype-like VoIP (obviously not in the interest of cellular operators), a voice recorder (for voice blogging purposes, perhaps?), games (I certainly would love MAME or ScummVM for iPhone), third-party media players (like VLC or MPlayer) and VNC (this might be possible with Web 2.0, albeit slowly). And many futuristic applications using the camera, microphone, Bluetooth or motion sensors are just not possible at the time being.

To see an example of what is feasible consider Google Docs & Spreadsheets. It is a powerful online office application that runs on the iPhone. And "iGoogle" is a personalized homepage with many customizable "Google Gadgets". It even accepts user-submitted gadgets.

It is clearly visible that Apple is heading in an open-standards, web-based direction. I myself can see many benefits in this move, as more and more online web applications might end up replacing traditional VPN systems with online, secure document viewing/editing and group collaboration tools. Might there be a big market about to be exploited?

The soul of a web application

How does one start writing a web application? Well, if you have something that serves web pages you are done, it'll work on the iPhone. I have always had a very good experience with AMP (Apache, mySQL and PHP), and do recommend it. You can easily find AMP (LAMP or MAMP) tutorials on the web. Other interesting frameworks are Ruby on Rails and Java+any application server.

As a first step, you should think about the web-app client-server communication. It will have a huge impact on people's patience (and maybe on their phone bills, too) if you transmit too much data. Remember the iPhone is GSM/EDGE.

The most straightforward approach is a classic HTTP request>response scheme. You display an HTML form, receive the variables from the form, and respond with the requested information. This simple approach works well for directory look-ups.

The problem with this scheme is complex interfaces that require minor screen updates (as a Web 2.0 office application certainly would). The overhead of HTML pages and forms will quickly render such a web-app unusable. Fortunately, one can use Ajax (Asynchronous JavaScript and XML) to solve this issue. JavaScript provides the XMLHttpRequest class that lets a web browser send asynchronous messages to a web server and receive a response. The JavaScript client on the browser can then update the page accordingly, with no reloading at all.

Let's see an example of a web page that automatically fills in a city name from a ZIP code. The HTML code for this example is:

<input type="text" id="zip" name="zip" onblur="getCityFromZip();"> <input type="text" id="city" name="city">

The onblur event starts the getCityFromZip() function when the user leaves focus of the zip field. Shown below is the JavaScript code that performs the look-up:

<script type="text/javascript" language="JavaScript">
// Create the HTTP object
function getHTTPObject() {
   var xmlhttp;
   if (typeof XMLHttpRequest != 'undefined') {
      try {
         xmlhttp = new XMLHttpRequest();
    } catch (e) {
         xmlhttp = false;
    }
   }
   return xmlhttp;
}
var http = new getHTTPObject();
// Look-up function
var url = "http://www.example.com/getCity.php?zip=";
function getCityFromZipcode() {
  var zip = document.getElementById("zip").value;
  http.open("GET", url+escape(zip), true);
  http.onreadystatechange = handleHttpResponse;
  http.send(null);
}
// HTTP response handler
function handleHttpResponse() {
  if (http.readyState == 4) {
    // Split the comma delimited response into an array
    document.getElementById('city').value = http.responseText;
  }
}
</script>

getHTTPObject() initializes the 'http' variable with an XMLHttpRequest object. A call to getCityFromZip() sets the request's http handler to handleHttpResponse(). It also starts a GET web request to:

   http://www.example.com/getCity.php?zip=[zipcode]

When the server answers, handleHttpResponse() takes over and updates the HTML element 'city' with the response from the GET request. In this example, the http response from the server is read directly. When you deal with complex data types an XML container might not be a bad idea.

How can you optimize your web-app? You can start by separating static and dynamic content. If static content is in a separate file it will be loaded only once, reducing data flow. You can get dynamic content with the XMLHttpRequest class described before. The same optimization can also be applied to JavaScript code. Consider creating a .js file for JavaScript code common to many URLs. Yet another optimization is to minimize the data flow of the dynamic requests: keep variable names short, keep URLs short. Try to bundle multiple dynamic requests to avoid HTTP overhead. Also, try to use HTTP GET requests, they have a smaller overhead than a POST (unless you have a lot of data). You can improve responsiveness by putting all user interface screens in a single .html file and using <DIV> styles to show only the one you currently need. It will take longer to load on the first time, but Safari caches content, so it will pay off soon. Final advise: enable gzip compression on the server, it helps when and if the browser allows it (Safari does). By following these guidelines, you will make many users happy.

The face of a web application

Now you know a little bit about the internals of good web-apps, but there is still something missing: the user interface.

It is unfortunate that so many developers disregard user interface design. Horrible, unintuitive apps are out there, and this is particularly true of mobile phone applications. I am sure you can make a difference. UIs are not just decor, they are what your users work with.

The iPhone screen

The iPhone screen is 320x480 pixels. At 160 pixels per inch, this is two by three inches. But HTML page width is not important, as iPhone's Safari is resolution independent (it adjusts page width automatically). It is nevertheless a good idea to limit HTML page width to 480 pixels, as this is the iPhone's largest native resolution.

You should also consider that your application can be viewed in either portrait or landscape mode. When viewed in portrait mode, an application gets approximately 320x355 visible pixels. In landscape mode, about 195x480 pixels are visible. When scrolling down, additional 60 or so pixels get available from the top of the title/address bar.

You should always choose font sizes that are easy to read in both portrait and landscape modes.

Controls

A great user interface is grandmother-proof. iPhone has one, so make no exception! A typical finger is 1/2 inch thick, so you should never pack more than 4 or 5 buttons in a row. The buttons should also be approximately the size of a finger.

When selected, text-entry fields open up the virtual keyboard. Consider resizing all HTML input elements so that they are easily accessible on the iPhone's screen.

In order to send an email from a form, link to a mailto: [email address] URI. At the time of this writing, this is unconfirmed, but most likely you can start a phone call by linking to a tel: [phone number here] URI (RFC 2806 standard).

Interaction

This is probably the most important, but also the hardest aspect to achieve, as it depends on the application. General guidelines are: keep everything as clean as possible. Never have more than eight user interface elements visible at the same time. The human brain is not good at dealing with more than eight things at once. You can use an <iframe> to emulate the iPhone's scrolling center part of the screen. Attempt to use the same symbols and logic as in the rest of the phone. Consider the flow of the different screens of your user interface. Is everything as simple as possible? Is it possible to accommodate your user interface so that users don't have to re-learn things they know from somewhere else?

Always keep asking yourself how your UI can be improved. And read Apple's Human Interface Guidelines, they are an excellent reference.

Eye candy

If you want to create a nice user experience, attempt to integrate your style with the iPhone's UI style. Split content and presentation with HTML/CSS (this will also reduce data flow). You can do pretty amazing animations in JavaScript. Check out this site for some examples: http://script.aculo.us/

An example under the spotlight

This article came to be because I was looking for an iPhone ssh client and simply couldn't find one. So, I started developing a Web 2.0 ssh client, as this was the one thing from keeping me buying an iPhone.

Luckily, I found the open-source Ajaxterm project. They were doing something similar to what I had in mind. Only the user interface had to be adapted.

So how does Ajaxterm work? It consists of a web client written in JavaScript, and a web server running in python. The web client periodically polls the server for screen updates. The web client also sends any key presses to the server.

What was needed to adapt Ajaxterm to the iPhone?

Ajaxterm gets key events through the JavaScript "onkeypressed" event. Unfortunately, this is not supported on the iPhone. Therefore, I added a text input control below the console screen, and several buttons for cursors, control and other special keys. The UI elements were arranged so the most common keys are close to where you actually work. The least used key combinations are hidden behind an alternative button control.

You can test the ssh client as well as download the source code at this URL:

http://www-personal.umich.edu/~mressl/webshell

What does the future hold?

In my opinion Web 2.0 (JavaScript + Ajax + XML + XHTML + RSS) is much more powerful than many believe. There are lots of limitations: no local storage, no access to iPhone's resources, limited computing resources, limited access to the multi-touch interface. But except for the applications discussed previously, I can't find a serious software limitation for iPhone.

Nevertheless, I hope that we will soon see a native iPhone software development kit. It will trigger a whole new generation of applications that we are not even capable of dreaming right now. Just imagine what a multi-touch controller with accelerometers and Bluetooth could do to a mobile game...


Marc S. Ressl is a senior developer in the cell phone business. He presently designs web applications using open-source technologies. He is also experienced in computer security and user interface design. You can reach him at mressl@umich.edu.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Tinderbox 8.1.0 - Store and organize you...
Tinderbox is a personal content management assistant. It stores your notes, ideas, and plans. It can help you organize and understand them. And Tinderbox helps you share ideas through Web journals... Read more
Microsoft Office 365, 2019 16.30 - Popul...
Microsoft Office 365. The essentials to get it all done. Unmistakably Office, designed for Mac Get started quickly with new, modern versions of Word, Excel, PowerPoint, Outlook and OneNote-... Read more
RoboForm 8.6.5 - Password manager; syncs...
RoboForm is a password manager that offers one-click login, mobile syncing, easy form filling, and reliable security. Password Manager. RoboForm remembers your passwords so you don't have to! Just... Read more
Amazon Chime 4.26.6995 - Communications...
Amazon Chime is a communications service that transforms online meetings with a secure, easy-to-use application that you can trust. Amazon Chime works seamlessly across your devices so that you can... Read more
EarthDesk 7.4.1 - $24.99
EarthDesk replaces your static desktop picture with a rendered image of Earth showing correct sun, moon, and city illumination. With an Internet connection, EarthDesk displays near-real-time global... Read more
Boom 3D 1.3.2 - $19.99
Boom 3D is a revolutionary app with 3D Surround Sound and phenomenally rich and intense audio that is realistic and works on any headphones. Features 3D surround sound Built-in audio player... Read more
Sketch 59 - Design app for UX/UI for iOS...
Sketch is an innovative and fresh look at vector drawing. Its intentionally minimalist design is based upon a drawing space of unlimited size and layers, free of palettes, panels, menus, windows, and... Read more
Alfred 4.0.5 - Quick launcher for apps a...
Alfred is an award-winning productivity application for OS X. Alfred saves you time when you search for files online or on your Mac. Be more productive with hotkeys, keywords, and file actions at... Read more
DiskCatalogMaker 7.5.7 - Catalog your di...
DiskCatalogMaker is a simple disk management tool which catalogs disks. Simple, light-weight, and fast Finder-like intuitive look and feel Super-fast search algorithm Can compress catalog data for... Read more
Adobe Premiere Elements 2020 18.0 - Cons...
Adobe Premiere Elements just got better. Now you can create quick movies from favorite parts of your clips or tell big life stories in full-on productions. Add motion inside movie titles, punch up... Read more

Latest Forum Discussions

See All

Hello Hero All Stars receives update wit...
The first Hello Hero game hit global platforms in 2013 and proved a huge success, with developer Fincon adding two more entries to this popular series of casual RPG games since. Released in June this year, Hello Hero All Stars brings many of the... | Read more »
Zombieland: Double Tapper, a cartoon idl...
Zombieland: Double Tapper is the idle RPG tie-in to the upcoming Zombieland: Double Tap. Oddly, it's one of two different Zombieland games launching today, with the other being the Switch title Zombieland: Double Tap - Road Trip. [Read more] | Read more »
Rusty Lake's The White Door launche...
Rusty Lake and Second Maze's intriguing point-and-click adventure game, The White Door, is now up for pre-order on the App Store. This one sees you playing as Robert Hill, a mental health patient who is suffering from severe memory loss. The game... | Read more »
Hellrule is an auto-runner inspired by G...
Hellrule is an upcoming auto-runner game from independent developer Pedrocorp where players will take control of a dapperly dressed gentlemen who comes equipped with a razor-sharp umbrella for slicing up his foes. The game will be available for... | Read more »
Grobo is a gravity bending puzzle platfo...
Grobo is a 2D puzzle platformer that marks the first release from developers Hot Chocolate Games. You'll find yourself manipulating gravity as you make your through this title that's available now for iOS and Android. [Read more] | Read more »
Adrenaline, Compulsive Entertainment’s h...
Compulsive Entertainment’s high-octane arcade racer, Adrenaline, has now made its way to the App Store following a successful launch on Google Play. It’s a ton of challenging, fast-paced fun, boasting easy-to-learn controls and a varied selection... | Read more »
Mario Kart Tour is adding Super Mario Ga...
Earlier today on Twitter, Nintendo announced that Mario Kart Tour is getting a new racer and track. Fans of Super Mario Galaxy will be pleased to hear that Rosalina is the first post-launch character being added, while the iconic Rainbow Road is... | Read more »
$100,000 up for grabs at World of Tanks...
The fourth annual Blitz Twister Cup will be held in Minsk (Belarus) on November 9th. For those not in the know, the Blitz Twister Cup is an eSports championship for the hugely popular World of Tanks Blitz. [Read more] | Read more »
Brown Dust’s crossover event with That T...
Brown Dust, Neowiz’s epic fantasy RPG, is no stranger to special events, though its latest crossover might be its most exciting yet. On top of a challenging new dungeon, fan-favourite characters from the hit anime series That Time I Got... | Read more »
Call of Duty Mobile first impressions: A...
After many months of waiting, Tencent and Activision’s Call of Duty Mobile is finally out. The ambitious twitch shooter looks to bring the core COD experience to mobile with few concessions. Achieving such a goal is no small feat, even with all... | Read more »

Price Scanner via MacPrices.net

Save up to $30 on Apple’s AirPods at these re...
Amazon is offering discounts on new 2019 Apple AirPods ranging up to $30 off MSRP. Shipping is free: – AirPods with Charging Case: $144 $15 off MSRP – AirPods with Wireless Charging Case: $169 $30... Read more
Save $15 on Apple Watch Series 5 models on Wa...
Walmart has new Apple Watch Series 5 models on sale for $15 off Apple’s MSRP on their online store. Choose free shipping or free local store pickup (if available). Sale prices for online orders only... Read more
Save $750 on the base 8-Core 27″ iMac Pro wit...
Apple has Certified Refurbished 27″ 3.2GHz 8-Core iMac Pros available for $4249 including free shipping. Their price is $750 off the cost of new models. A standard Apple one-year warranty is included... Read more
Apple continues to offer 11″ iPad Pros, refur...
Apple has Certified Refurbished 11″ iPad Pros available on their online store for up to $220 off the cost of new models. Prices start at $679. Each iPad comes with a standard Apple one-year warranty... Read more
Get Beats Solo3 Wireless Headphones today for...
Amazon has Beats Solo3 Wireless On-Ear Headphones in stock and on sale today for $139.99 shipped. Their price is $60 off Apple’s MSRP, and it’s the lowest price available for this model from any of... Read more
Sale! 2019 13″ MacBook Airs for $200 off Appl...
Amazon has new 2019 13″ MacBook Airs on sale for $200 off Apple’s MSRP, with prices starting at $899, each including free shipping. Be sure to select Amazon as the seller during checkout, rather than... Read more
Verizon offers $150 discount on iPhone 8, 8 P...
Use code SMART150 at checkout at Verizon to take $150 off the price of an iPhone 8, iPhone 8 Plus, or iPhone X. New line of service required. Their discount reduces the price of a 64GB iPhone 8 to $... Read more
38mm Apple Watch Series 3 GPS model on sale f...
Amazon has 38mm Apple Watch Series 3 GPS models available for only $189. Choose Amazon as the seller rather than a third-party, and note that Amazon stock fluctuates, so be sure to check their site... Read more
13″ 1.6GHz/128GB MacBook Air on sale today fo...
Amazon has new 2019 13″ 1.6GHz/128GB Space Gray MacBook Airs on sale for $100 off Apple’s MSRP, only $999, including free shipping. Be sure to select Amazon as the seller during checkout, rather than... Read more
Trade in your iPhone 6 at Verizon and get $10...
Holding onto an older iPhone 6 or 6s and ready to upgrade to a new Apple iPhone 11? Verizon is offering Apple’s new iPhone 11 models for $300 off MSRP to new customers with an eligible trade-in (see... Read more

Jobs Board

Best Buy *Apple* Computing Master - Best Bu...
**741153BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000411-Flint-Store **Job Description:** **What does a Best Read more
Surgical Technologist III, *Apple* Hill Sur...
Surgical Technologist III, Apple Hill Surgical Center - Full Time Tracking Code APPHILLST Job Description Surgical Technologist III Apple Hill Surgical Center 25 Read more
Geek Squad *Apple* Master Consultation Agen...
**741154BR** **Job Title:** Geek Squad Apple Master Consultation Agent **Job Category:** Services/Installation/Repair **Location Number:** Read more
Best Buy *Apple* Computing Master - Best Bu...
**740900BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Store Associates **Location Number:** 000387-Randall Road-Store **Job Description:** Read more
Best Buy *Apple* Computing Master - Best Bu...
**735122BR** **Job Title:** Best Buy Apple Computing Master **Job Category:** Sales **Location Number:** 000405-Saginaw-Store **Job Description:** **What does a Best Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.