Friday, November 14th, 2008

Using UIWebView (WebKit) in your iPhone App

Category: iPhone, Mobile

Dr Nic has shared his experiences using WebKit to implement part of your iPhone app (in his case SurfView):


  • - (void)webViewDidFinishLoad:(UIWebView *)webView is slow. “You’re running an interpreter (JavaScript runtime) on top of a device with a small CPU and small memory. Go figure.”
  • The JavaScript bridge does not appear to block the main thread. This is a good/bad thing. You can invoke JavaScript code within the WebKit via your native Objective-C code.
  • The JavaScript bridge is one directional. From Objective-C/UIKit you can invoke JavaScript upon the WebKit and henceforth do wonderful things
  • Multiple languages in one project. Whilst we mainly just wanted to take a static HTML file, and dynamically update various elements with application data (e.g. the surf and weather conditions in the example above), we needed to do that via JavaScript.

Why you may want to do it

WebKit for rapid prototyping: WebKit exists and it is awesome at rendering HTML and CSS, with access to the powerful CSS3 transformations and webkit-specific bonus features.

It is highly likely that your designer can make something beautiful looking in Photoshop and cut it up into HTML + CSS. Comparatively, its highly unlikely they can cut it up into native Objective-C code.

WebKit isn’t the holy grail for non-Objective-C developers, but if your grand-poobar level skills are in JavaScript and HTML, and your Objective-C/iPhone skills are still catching up, then its a wonderful prototyping platform. Especially for static, complicated displays of data. Especially if that data includes HTML content from an external feed which needs to be rendered.

For Oakley’s Surf Report app, Anthony is toying with replacing some of the WebKit usage with native UI elements (normal UITableView with custom UITableViewCells) so that we can get back those precious seconds and give them to the user as a Christmas present.

A very nice read.

Posted by Dion Almaer at 8:21 am

3.9 rating from 17 votes


Comments feed TrackBack URI

is it just me or UIWebView is very, very unstable with more advanced websites? I’m pretty sure it’s the main reason of crashing apps using it.

Comment by mrgreengo — November 14, 2008

Anyone tried PhoneGap?

Comment by Nosredna — November 14, 2008

Or try Big Five if want to avoid as much Objective-C programming as possible using web techniques:

Comment by perenzo — November 17, 2008

Or you can try LiquidGear to use native front-end with no Obj-C.

Comment by nitrog7 — April 21, 2009

Leave a comment

You must be logged in to post a comment.