iPhone Magic
Recently i’ve been playing about with the iPhone SDK. I’m actually quite impressed at the great tools included to make development easier, whether you choose to develop native applications or web applications.
Since i wasn’t quite up to scratch with my Objective C, i thought i’d see how much better the in-built browser was. Using Dashcode, i was easily able to prototype some pretty neat touch-based interfaces.
Still, one of the major criticism’s i seem to find about developing web apps for the iPhone is a lack of an off-line option. If you aren’t connected to a network, you can’t make use of any web applications.
Well, that’s not strictly true. You can use the “data:/” URI hack, where you bookmark a URL containing the HTML of the application you want to use off-life. But this is not a very useful solution if you want to store persistent data your application can use after re-loading.
Which is why i was pleased to find out that the iPhone simulator in the SDK includes support for WebKit’s new Database storage API. In essence this means that you can persistently store pretty much anything you want on the client.
How is this useful on the iPhone? Well, it means we can now make very useful offline web applications with persistent data storage.
Here is the “proof of concept” i have cooked up.
http://www.cuppadev.co.uk/iphone/database-images/
If you visit the above URL in the iPhone simulator, you should see three items which you can click on. (Note that these are all data:/ URI’s)
- The first creates a database (if it does not already exist) and stores the data for an image, which is then loaded back and shown on the page.
- The second inserts a second image into the database. If you click on the first item again, there will now be two images shown on the page.
- The third replaces the data of the first and the second image. If you click on the first item again, you might get a little shock.
There are of course limitations to this Database API. Access to databases is restricted on a per-domain basis (although in Webkit “data:/” URL’s are treated as a single domain), and on the iPhone simulator you only get up to 5mb of storage.
Still, it works and i can see it being a very useful feature for future web applications on the iPhone.
This actually works in Safari 3.1 too, so you don’t need to download the huge iPhone SDK to try this out. It technically should work in Firefox 3 too, though as of yet i haven’t managed to get it to allow access to the database.
