Mobile Spec is here | November 4th, 2009
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
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!
November 4th, 2009 at 10:36 pm
[...] This post was mentioned on Twitter by dave johnson, Fil Maj. Fil Maj said: Mobile spec (aka test suite) is here for PhoneGap! http://bit.ly/2k4IzN [...]
November 9th, 2009 at 10:43 am
Hey Fil,
I really want to use PhoneGap as a solution for Blackberry apps, but I can’t think of a workaround for the xmlhttprequest not working…any suggestions on how I could call a web service without it?
November 9th, 2009 at 10:53 am
Brian,
Sure is! The solution is in the PhoneGap repository on GitHub. What I did is I implemented an HTTP request/callback mechanism, very similar to a classic XMLHttpRequest, in the BlackBerry native code. It’s wrapped up in the NetworkCommand implementation of the BlackBerry PhoneGap source (see http://github.com/phonegap/phonegap/blob/master/blackberry/src/com/nitobi/phonegap/api/impl/NetworkCommand.java).
Here’s the JavaScript API implementation for it, taken from the BlackBerry phonegap.js file at line 1073:
// Temporary implementation of XHR. Soon-to-be modeled as the w3c implementation.
Network.prototype.XHR = function(URL, POSTdata, successCallback) {
var req = URL;
if (POSTdata != null) {
req += “|” + POSTdata;
}
this.XHR_success = successCallback;
PhoneGap.exec(”network”,["xhr",req]);
};
So, Brian, you would call something like this from your code:
var win = function(data) {alert(data);};
navigator.network.XHR(’http://www.myservice.com/?param1=value1′,null,win);
The second argument to the XHR function is text data to send as POST data in the request. Eventually, I am going to re-wrap this to mimic, as close as I can, the ‘usual’ XHR implementation that we’re all used to.
Hope that helps!
Fil
November 10th, 2009 at 6:37 am
Hi Fil,
Thanks again for your help with this….unfortunately I still can’t get this to work, allow me to show you what I’m trying to accomplish here:
I set up a simple test web service that has a HelloWorld method.
Then I set up a test function that is called on a button click:
function test() {
alert(’before call’);
navigator.network.XHR(’http://localhost:4023/Service1.asmx/HelloWorld’, null, win);
alert(’after call’);
alert(’before function’);
var win = function(data) {
alert(data);
};
alert(’after function’);
}
I then added an alert in the Network.prototype.XHR function (in phonegap.js) just to make sure it was being called — and it is in fact being called on my button click.
The problem is that the success handler is not getting called. All my alerts before and after each step do come up.
Is there a later release of phonegap that I should be using?
Any insight into my problem would be greatly appreciated.
Thanks…Brian
March 30th, 2010 at 1:40 pm
Hi,
Maybe it is a bit late Brian, but the same happened to me, so I leave this for future references:
Data passed to the callback function, that is data returned by the http-get to the URL MUST be a JSON. Something like this would work fine:
var win = function(data) {
alert(data.text);
};
navigator.network.XHR(’http://localhost:4023/Service1.asmx/HelloWorld’, null, win);
Where the data returned by the “Service1.asmx/HelloWorld” service is something like:
“{text: ‘Hello world’}”
Hope this helps!
May 3rd, 2010 at 6:43 am
Hi
i am using the below XHR in balckberry.I am getting alert message in callback function.Response returns as [object object].i want to call xml file.please help me to parse it out
sample xml:
?
?
1.jpg
video
1.35
?
Code:
function doXHR() {
alert(’in’);
var testURL = “http://www.google.com”;
var postDATA = null;
var callback = function(response) {
alert(’call back’);
// Do stuff with the response data…
alert(response);
};
navigator.network.XHR(testURL, postDATA, callback);
}