Blog
Android 1.5 to 2.0 Support in EDGE
Thu, Nov 26, 2009
by
Joe B

After spending a day with Java reflection, I believe that we are now at the point where PhoneGap Android can now be supported on 1.5, 1.6 and 2.0 versions of Android. This wasn’t incredibly hard, except for the fact that I was unfamiliar with reflection, and the example on the Android site is less than helpful, since it deals with the Debug static methods, and not a real world object that can have things like instances. Also, reading Sun’s documentation made me realize how useless examples that use the word Class is as a classname.

The result of this is that we may have a JAR that can be used on Android 1.5, 1.6 and 2.0, which solves the divergence issue. However, this doesn’t mean that we have SQLite database storage that doesn’t exist on Android 1.5 or 1.6. It means that if you are using Android 2.0, you have access to the SQLite Database if you are running the Edge version.

After pairing down PhoneGap to a jar, it appears to be weighing in at under 200k. I’m thinking about distributing it as an installable library on Android so that if you have it installed, you can download PhoneGap compatible APKs. This would be similar to the Text-To-Speech API functionality. This may encourage Google to close the browser gap, or it may just get ignored if people just use their own stand-alone PhoneGap + app apps.

More info on this will come shortly.


› Visit the original post

PhoneGap Mobile Spec tests on iPhone
Tue, Nov 24, 2009
by
shazron

Fil who has been working on the Mobile Spec came over and we tested the mobile spec on the current (EDGE) version of iPhone PhoneGap, and the tests look pretty sweet (see video).

It was pretty easy, I created a new Phonegap-based Application from the Xcode template, plopped in the contents of the Mobile Spec, and just ran the app in the iPhone Simulator. In this session, we see that iPhone PhoneGap passes 51 out of 64 tests, for a 79% pass rate.


› Visit the original post

Contributing to iPhone PhoneGap – Part 1
Mon, Nov 23, 2009
by
shazron

There has been a major re-factoring of the iPhone PhoneGap codebase, to better enable users to get a current version of PhoneGap to use in their projects without mucking about in the core PhoneGap code.

You can view the code here: http://github.com/phonegap/phonegap/iphone

The README has more details, and I will elaborate on it more here, especially on how contributors can add to the code.

PhoneGapLib/javascripts/core
This is where you will add/modify your javascript code for PhoneGap core. You can add more javascript files here, but make sure you update the “PhoneGapLib/Makefile” file to include the newly added javascript file. For adding the file in the Makefile, the pattern should be obvious.

PhoneGapLib/Classes
This is where you will add/modify your Objective-C code for PhoneGap core. You can add more Objective-C files here, but make sure you add it to the PhoneGapLib Xcode project also.

PhoneGapLib/javascripts/phonegap.js
This is dynamically generated, and is generated whenever PhoneGapLib is built. You can update this file by running “make” in the PhoneGapLib folder, but generally it should be called in your application that includes PhoneGapLib (which the PhoneGap-based Application Xcode template does).

I will walk you through how to add a new command, by adding Application Preferences support. Download the files here.

Preferences.h

@interface Preferences : PhoneGapCommand {
}
- (void) boolForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options;
// other functions here

@end

Note that the class inherits from PhoneGapCommand. The class name you use here is important, since you will be referring to it in javascript.

To ‘expose’ a function to javascript, it must have the signature from the example ‘boolForKey’ method above (first argument is a NSMutableArray, the second argument is a NSMutableDictionary).

Let’s now look at the javascript command to access the function above.

preferences.js

function PreferencesManager() { }

var g_Preferences = new PreferencesManager();
PreferencesManager.sharedPreferences = function() {
	return g_Preferences;
}

PreferencesManager.prototype.boolForKey = function(key, callback) {
	PhoneGap.exec("Preferences.boolForKey", key, GetFunctionName(callback));
}

The important line is the “PhoneGap.exec” line. The first argument to PhoneGap.exec is in the form of <className>.<methodName> (refer to Preferences.h to see the corresponding function which should be obvious). The next arguments to PhoneGap.exec are two strings, which will be passed into the “boolForKey” method in the NSMutableArray which is the first argument. If an object (json object) is passed in as an argument to PhoneGap.exec, that data will be passed into the “boolForKey” method in the NSMutableDictionary which is the second argument.

Preferences.m

- (void) boolForKey:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
	NSUInteger argc = [arguments count];
	if (argc < 2) { // no key and/or callback - just return, no point in continuing
		return;
	}

	NSString* key =  [arguments objectAtIndex:0];
	NSString* callback = [arguments objectAtIndex:1];

	NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
	BOOL value = [userDefaults boolForKey:key];
	NSString* retVal = value ? @"true" : @"false";

	NSString* jsString = [[NSString alloc] initWithFormat:@"%@('%@', %@);", callback, key, retVal];
	[webView stringByEvaluatingJavaScriptFromString:jsString];
	[jsString release];
}

In the command itself, you can parse the arguments and options, and do whatever you need to do for your command. You can optionally write javascript back, using the method above, or the helper:

 [super writeJavascript:@"alert('foo')"] 

Next: Adding your code to PhoneGapLib.


› Visit the original post

PhoneGApp Store Approval
Fri, Nov 20, 2009
by
Jesse

I just received word from Apple that :

a) Apple has given PhoneGap a technical analysis , and PhoneGap does not violate the Terms & Conditions of the App Store.
b) Apple will review PhoneGap applications based on their own merits and not on their use of PhoneGap.

What this means:

There was still some apprehension within the community as to whether or not using PhoneGap would lead to a possible rejection from the iPhone App Store, we definitely have a green light to PhoneGap. This means we can all get back to doing what we love best, building fast, easy mobile apps with JavaScript+HTML+CSS while still taking advantage of the core features in the iPhone, Android, Symbian-WRT and Blackberry devices.

Happy coding!


› Visit the original post

PhoneGap for Symbian: Qt
Wed, Nov 18, 2009
by
Ryan

During the initial stages of working on PhoneGap for Symbian using Web Runtime, some limitations were brought to light due to the fact that Nokia’s WRT is closed source: we are limited to the device functionality and platform support which Nokia has exposed. Nonetheless its a great technology and porting PhoneGap to WRT was a relatively quick win (taking in to account my having to re-learn javascript after 1 year of flailing abroad).

But over the last few weeks, while maintaining the latter, I’ve been researching/experimenting (don’t even want to go far as say developing, as very little has been implemented) with Qt for Symbian. The crew at Nokia just released the Qt 4.6 release candidate on Nov 17th, and it includes a port of Webkit to Qt (QtWebkit), along with support for the Symbian/S60 platform, which is just the combination phonegap needs.

note my amazing javascript console, firebug is crap

note my amazing javascript console, firebug is crap

So anyways I’ve got a PhoneGap Symbian Qt build (piggybacking off of the webkit demos included with Qt) which can open a local resource in a webview, and expose Qt Objects (and thus device functinoality) to javascript (via webframe->addtojavascriptwindowobject). I’ve implemented the most important API first, rather than the easiest: vibration. Ok it was actually the easiest.

Anyways there’s other problems to tackle before implementation of more PhoneGap APIs:

  • XHRs seem to be getting blocked. I’m thinking its blocking what it considers a cross-domain XHR: a local html file to a remote server. I believe the support of this depends on the Webkit implementation(?)
  • I can’t remember what else.

So if this looks interesting, help out the mobile developer community. Contribute. Its open source. Check out my very basic Getting Started doc, and get the code from my PhoneGap repo on Github (Symbian Qt branch). The .sis installer file is in there as well, so you could also just put it on your device to see a PhoneGap app that vibrates and thats about it. Really useful. I think you might need to install Qt libraries to your phone since I haven’t packaged them in the app yet.


› Visit the original post

XUI Sweeter then ever.
Thu, Nov 5, 2009
by
silentrob

With so much buzz around the office about PhoneGap, I figured I would chime in too, call it a spite driven blog post.

Last week I decided to add some sugar to XUI our answer to a light weight JavaScript framework. Since XUI really doesn’t need any new functionality it is really about progressively enhancing the existing code and project.

One area of the code I felt was particularly lacking was how XUI dealt with FORMS, and specifically how we could make XHR handle forms automatically. So lets start by looking at an example of how it worked before.

// This will insert data.html into #some_div
$('#some_div').xhr('/data.html');

When this code runs, it will see that the XHR function has no options, and send the resulting responseText back to the DIV (blowing out the existing content – innerHTML)

$('#some_div').xhr('/data.html', function() { alert("XHR Fired"); });
By making a simple change and passing in a function as the second parameter, you get the responseText back in the callback, this circumvents the responseText from being passing back to the calling node, making it arbitrary.

$('#some_form').xhr(function() { alert("XHR Fired"); });

<form id='some_form' action='/data.html' method='post'>
<input type='text' name='foo' value='bar' />
</form>

With the new changes from my last commit you now have both. In this case, the XHR function checks to see if node is a form, and then uses that data to construct the XHR request, action, method and form properties are all taken into account. Once the XHR has completed, it will call the callback function.

To learn more about XUI visit XUI
Check out the code here http://github.com/silentrob/xui

Thanks.


› Visit the original post

Mobile Spec is here
Wed, Nov 4, 2009
by
Fil

The big thing around the office for the past year or so now has been PhoneGap. It’s gaining in popularity every day, and recently we’ve had applications starting to trickle into application stores other than the iPhone one! We now have one application out in the Nokia Ovi store, and one on the BlackBerry App World. I’m pretty excited to see PhoneGap getting a lot of mention all over the place, but this also puts more pressure on the PhoneGap team to have a solid framework that works consistently across all of the platforms that we support currently: iPhone, Android, BlackBerry and (some) Nokia models.

Mobile Spec running on a BlackBerry simulator

Mobile Spec running on a BlackBerry simulator

With PhoneGap being an open-source project, it is sometimes difficult to devote a lot of time to it all at once, and development coming in from user contribution is huge. One thing that is certain about open-source projects, especially ones where there are many contributors and an open development philosophy is used, is that having a set of tests is fairly essential. If developers wants to hop in and help out, in any way that that may be, they need to be sure that the changes they make don’t break the entire application. This becomes even more important as a project gets bigger.

So after that long-winded introduction, I want to point people’s attention to the new Mobile Spec that we have started to work on. You can find it on GitHub. Joe, our main PhoneGap Android developer, has his own fork of it that he’s started to fill up with tests, so we’ve made and are currently making progress on it. Yes! I love automatic regression testing – call me a geek, but I can’t help but have a warm fuzzy feeling inside knowing that test cases for something I’m working on are constantly trickling in :) . Obviously, the spec is in its infancy stages, but it’s a big win. The more we put into it, the easier it will be to develop for it down the road, and the more it solidifies the stability of PhoneGap overall.

Since day 1, PhoneGap’s goal has been for PhoneGap to cease to exist. That is, if all of the big players in the mobile space suddenly decided to work together and unify their third-party application development process, then PhoneGap wouldn’t need to exist as a project. Related to this, the PhoneGap JavaScript API is mostly based off of the HTML 5 specification – open standards are good and healthy for the developer community. What I’m getting at is that the Mobile Spec we’re putting together – maybe / potentially / hopefully – may end up being a decent test suite for the HTML 5 spec, or at least the mobile portion of the spec. Or maybe I’m just too optimistic ;)

We’ve opened this thing up to the community and we want to hear what you guys think. Have a beef with the API? Fork the mobile spec on GitHub, change it to what you think it should be, and then send us a pull request. We’ll definitely have a look.

Here’s to many forks! Cheers!


› Visit the original post

PhoneGap for iPhone exposed
Wed, Nov 4, 2009
by
Jesse

Earlier this week I attended the Apple iPhone Developers Tech Talks in Seattle. The event was free and by invite only and you had to have an app in the app store, or be very close to having one to be invited. This meant that the content of the talk could be technical without losing anyone, and we had an informative deep dive into technical things like OpenGLES, Device Audio, and UIKit functionality best practices. I learned a lot over the day about what to avoid, and how to optimize iPhone applications.

As a PhoneGap developer, user and evangelist, I made it my duty to talk to everyone I could about PhoneGap and guage the level of interest from the Apple dev community. After speaking to a couple people at Apple, it became clear that they are very much aware of PhoneGap, but have very little understanding of what it does or how it works. I have decided to dig into these questions to make sure that there are no misconceptions about the project.  PhoneGap is entirely opensource, but not everyone has the time read a bunch of code. ( if only …)

PhoneGap Under the Hood

PhoneGap aims to provide a consistent interface to device functionality across multiple platforms to enable rapid application development via well known technologies, namely HTML / JavaScript / CSS.

At it’s core, PhoneGap is nothing more than a spec listing JavaScript accessible calls that an application programmer can use to make applications. Each device ( iPhone, Android, BlackBerry, … ) has it’s own specific implementation, and the tools and processes you use to build, test and deploy/submit your app will vary for each. So again, PhoneGap is a JavaScript accessible API implemented on multiple devices.

All implementations render their user interface using HTML and CSS in a web browser control of some sort. Most modern devices support rich rendering features ( HTML5, CSS3 ) so it is a relatively simple to design, and layout your application with your existing skills, tools, and even existing graphical assets.

The typical PhoneGap application is a packaged version of a webpage/website that runs from the phone. What this means is that all html/css/js files are bundled into the application and run from the file:// protocol. A common misunderstanding is that the application is loaded over the web, which is definitely NOT the way we recommend users write their apps, and (to my knowledge) NOT the way typical PhoneGap based applications are architected. In this case you would be writing a mobile-optimized website and will likely not be approved for app store submission.

In some cases PhoneGap applications have a server component that delivers data via an HTTP API, usually json or xml using XMLHttpRequest. PhoneGap itself does not provide any server communication functionality, so app developers must roll their own server access layer.

So How Does PhoneGap Work?

Every device implementation has it’s own specific means of accessing device functionality, so I will be focusing on the iPhone implementation. The iPhone implementation is probably the most misunderstood, and most used, plus it is where I have spent the most time.

How does JavaScript call Objective-C code?

In order for a developer’s application code (js) to access device functionality they will include the file phonegap.js in their (html) application. The file phonegap.js defines the entire API and contains the key functionality for device communication. All device functionality that PhoneGap exposes is done via the navigator object in JavaScript.
For example, to access Accelerometer functionality, you would call JavaScript methods on the navigator.accelerometer object.

In order for phonegap.js to send a request to the device it simply sets the location of the page based on the following protocol:

gap://CommandHandler.method?arg1Name=arg1Value&arg2Name=arg2Value

gap://
This is a phonegap request and not a request to load a new page.
CommandHandler
This is a subset of device functionality that contains methods. An example would be Accelerometer or Notification
method
Each CommandHandler defines it’s own methods
arguments
a URL encoded list of arguments that are passed to the method ( varies based on the method ) Note that phonegap.js will URLEncode the parameters for you.

and here’s a concrete example:

gap://Notification.alert?message=Hello&title=My%20App%Name&buttonLabel=OK

This will call the Notification objects alert method, passing it a message,title, and the text to display on the button.

So, upon receiving the command, Objective-C code will take over and perfom the requested command.

So How Does Objective-C call my JS code?

Some calls from JS require a callback mechanism to let the JS code know when the command has completed, if it succeeded and so on. The majority of this is handled for the developer in phonegap.js. Objective-C code will call stringByEvaluatingJavascriptFromString() to pass data back into the js code. The mechanism for each command is defined in phonegap.js, so the developer will simply pass a function callback that phonegap.js will call once the command has returned data.

Here is a concrete example:

In my application, I want to access the accelerometer, so I define a callback function :


function onAccelData(accelObj)
{
// accelObj has properties x,y,z that you can use to see the
// current state of the accelerometer so presumably you
// would do something with that data here.
}
function onAccelFail()
{
// accelermeter functionality is not available,
// do something else ...
}

In order recieve the data, I need to make a call to the js Accelerometer object :

navigator.accelerometer.watchAcceleration(onAccelData, onAccelFail);

Now, your callback is going to be called repeatedly with updated accelerometer data, that your application can use as you see fit. Since this is not intended to be a blog post about how to use the accelerometer, I will stop there. You should know also that the accelerometer supports stopping as well, and you can also specify how often you want to be updated.

So that, in a nutshell, is the entire iPhone implementation of PhoneGap. Note, there is no voodoo or magic sauce, just 2 data transfer mechanisms and a protocol between them.
Hopefully this will give better perspective and help anyone who has to answer the question: What is PhoneGap?

Remember that PhoneGap is completely opensource so if you want a deeper look under the hood, you are completely free to do so.

If you want to use PhoneGap, you can git it here :http://github.com/phonegap/phonegap
To read more, have a look at www.phonegap.com

I invite your questions, comments, criticism, accolades, beers!


› Visit the original post

Tcktcktck (made w/ phonegap) available in ovi store
Wed, Nov 4, 2009
by
Ryan

The Tcktcktck mobile application is now published and available in Nokia’s Ovi Store to a selection of several S60 5th Edition devices. I believe it was recently approved in Blackberry’s app world, so once the iTunes Store sorts itself out, we’ll have a bit of a success story using PhoneGap for cross-platform mobdev!

PS the canucks are winning with half their forward lineup, plus luongo, injured. Bieksa even played forward last night haha! they’re makin a run.


› Visit the original post

PhoneGap Simulator Update
Tue, Nov 3, 2009
by
Yohei.Shimomae

PhoneGap Simulator Update
› Visit the original post