PhoneGap is one of the best projects to come out of iPhoneDevCamp II. It seems absolutely perfect for web developers who haven’t yet gotten comfortable with writing iPhone applications in Objective-C:
PhoneGap is a free open source development tool and framework that allows web developers to take advantage of the powerful features in the iPhone SDK from HTML and JavaScript. We’re trying to make iPhone app development easy and open. For many applications a web application is the way to but in Safari you don’t get access to the native iPhone APIs, and the that’s the problem we’re trying to solve.
It is written in Objective-C and allows developers to embed their web app (HTML, JavaScript, CSS) in Webkit within a native iPhone app. We’re big advocates of the Open Web and want JavaScript developers to be able to get access iPhone features such as a spring board icon, background processing, push, geo location, camera, local sqlLite and accelerometers without the burden of learning Objective-C and Cocoa.
Wrapping the WebKit library in a pre-built Cocoa shell enables two big things:
- Web developers can create a native, network-aware application that can be distributed and installed on the iPhone
- The javascript in these applications can access special iPhone features (Ie. location and accellerometer data) that normal web apps cannot
Here’s some of the iPhone API that’s exposed in Javascript by PhoneGap:
Geo Location
//request location – this triggers a subsequent method call to gotLocation(lat,lon)
getLocation();//GAP will invoke this function once it has the location
function gotLocation(lat,lon){
$(‘lat’).innerHTML = “latitude: ” + lat;
$(‘lon’).innerHTML = “longitude: ” + lon;
}Accelerometer
//You have instant access to the accellerometer data via the accelX, accelY, and accelZ variables
function updateAccel(){
$(‘accel’).innerHTML = “accel: ” + accelX + ” ” + accelY + ” ” + accelZ;
setTimeout(updateAccel,100);
}
Of course, this is open source. So in addition to the pre-built functionality, folks who can swing a little bit of Objective C can build on the PhoneGap codebase and provide Javascript access to other embedded features on the device.
ADVERTISEMENT