BizTalk Utilities CV ,   Jobs ,   Code library
 
Go to the front page to continue learning about XML or select below:

Contents

ReBlogger Contents

Previous posts in WS, web services

 
 
Page 3279 of 21350

PhoneGap: “AIR for the iPhone”

Blogger : Ajaxian Blog
All posts : All posts by Ajaxian Blog
Category : WS, web services
Blogged date : 2008 Sep 22

Dave Johnson calls PhoneGap "AIR for the iPhone" because this nice little hack, first created at an iPhone BarCamp, wraps the Web view with a container. This container gives the view access to APIs available on the device, that may not be available yet via WebKit alone. AIR provides a similar container for Flash and Ajax content on the desktop.

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.

PhoneGap also has a web app that allows web developers to quickly package their web app into a native iPhone app by providing a URL, a name and icon graphic the web service with automagically create a native iPhone application. We haven't open sourced that code but we're going to soon.

PhoneGap was conceived at iPhoneDevCamp II by Nitobi developer Brock Whitten, Rob Ellis, freelance designer Colin Toomey and Eric Oesterle.

There are a few APIs available now, and others pending:

JAVASCRIPT:
  1.  
  2. // Location API
  3. // Feels a little ugly compared to passing in a closure. Using a hard coded name? :)
  4.   getLocation();
  5.  
  6.   //GAP will invoke this function once it has the location
  7.   function gotLocation(lat,lon){
  8.     $('lat').innerHTML = "latitude: " + lat;
  9.     $('lon').innerHTML = "longitude: " + lon;
  10.   }
  11.  
  12. // Accelerometer API
  13.  
  14.   function updateAccel(){
  15.     $('accel').innerHTML = "accel: " + accelX + " " + accelY + " " + accelZ;   
  16.     setTimeout(updateAccel,100);
  17.   }
  18.  
  19. // Camera (pending)
  20.   function takePhoto(){
  21.     var photo = gap:takePhoto();
  22.     return photo;
  23.   }
  24.  
  25. // Vibration (pending)
  26.  
  27.   function vibrate(){
  28.     gap:vibrate();
  29.     return false;
  30.   }
  31.  

You can take a peak at the open source code on github. For example, here is the code that wraps the iPhone location service:

[c]
@implementation Location

- (id)init{
NSLog(@"Gap::Location");
locationManager = [[CLLocationManager alloc] init];
[locationManager setDelegate:self];
return self;
}

+ (void)startTracking{
NSLog(@"starting location tracker");
[locationManager startUpdatingLocation];
}

+ (void)stopTracking{
NSLog(@"stopping location tracker");
[locationManager stopUpdatingLocation];
}

- (void)location{
NSLog(@"location is");
}

- (void)log{
NSLog(@"the location is...");
}

- (void)dealloc {
[locationManager release];
[super dealloc];
}

@end
[/c]


Read comments or post a reply to : PhoneGap: “AIR for the iPhone”
Page 3279 of 21350

Newest posts
 

    Email TopXML