Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AJAX XML not working on BlackBerry with Web-Works or Phonegap

I've built an application which loads statistics from an external xml file on the web.

It works fine in the web browser. It also works fine when I package it with PhoneGap for Android. Works on BlackBerry Playbook as well.

However it doesn't work when I package it for BlackBerry. I have tried both WebWorks Command Line Tool and PhoneGap.


When I Package with WebWorks and Run on Simulator

The console on Web Inspector gives me the error

"Failed to load resource: the server responded with a status of 500 (Error requesting resources.)"

When I Package with Phonegap and Run on Simulator

When I package with PhoneGap instead of WebWorks I get the following errors poping up in alerts...

gap : ["Network Status", "getConnectionInfo","Network Status0",true]

gap: ["Device","getDeviceInfo","Device1",true]

gap_init:

gap_callbackServer:

gap_poll:

Live version of App (uncompiled)

ZIP file to run in WebWorks or Phonegap


similar unanswered question.


Youtube Video of Problem in BlackBerry Simulator


Things I've Tried

I've added to my config file.

<access subdomains="false" uri="*"/>

I've added a $.support.cors function suggested by phonegap.

$( document ).bind( "mobileinit", function() {
    // Make your jQuery Mobile framework configuration changes here!
    $.mobile.allowCrossDomainPages = true;
});
like image 929
Philip Kirkbride Avatar asked Jan 16 '23 13:01

Philip Kirkbride


2 Answers

Is your simulator and WebWorks SDK up to date?

I've tested on a live PlayBook with 2.0.1.358 and in the simulator for 2.0.0.7971 with no problems that I can see.

I packaged with the 2.2.0.15 WebWorks for PlayBook SDK, and the only thing I changed was the id in config.xml, which wasn't accepted in the packager with the dots.


Okay, now I see what the problem is.

It's pretty obscure, but the Java Smartphones sims are setup to work with another old simulator tool called the MDS Simulator. It's not really necessary for most things, but provides networking similar to what a device sees in a Corporate BES environment. The simulator believes it has what is called an "MDS" connection all the time even if the MDS Simulator isn't running.

With a WebWorks app, if you use a default config.xml file with no <rim:connection> tag (which is totally fine for most cases), it prioritizes MDS before the TCP options. This is a problem because the sim thinks it has an MDS connection when it actually doesn't and that connection attempt eventually fails.

If you add the following bit of code to your config.xml, it will reduce the priority of MDS and should make it work just fine.

<rim:connection timeout="60000">
    <id>BIS-B</id>
    <id>TCP_WIFI</id>
    <id>TCP_CELLULAR</id>
    <id>MDS</id>
    <id>WAP2</id>
    <id>WAP</id>
</rim:connection>

And one last Critical item - you need to set up the simulator to use the simulated wifi network. Click on the top banner of the homescreen (by the wireless indicator), then turn on Wifi, and click on Wi-Fi Network in Options and Status. Then Click on Default WLAN Network and go through the steps to associate it.

like image 185
Tim Windsor Avatar answered Jan 30 '23 21:01

Tim Windsor


I assume this has to do with the setup calls near the end of your webworks.js. I'm not sure where you got this library, but it seems a little old.

WebWorks should expose the javascript APIs that you request in your config file automatically (ie: window.blackberry.*) without the need to make requests like you have to http://localhost:8472/blackberry/extensions/get.

Since you're just making ajax calls, I'd drop all of that and focus on debugging your ajax code.

PS: Phonegap works on top of WebWorks, so abstracting things further won't likely solve your problem.

like image 45
Wes Johnson Avatar answered Jan 30 '23 19:01

Wes Johnson