Phonegap API not responding to calls (iPhone)

19 views
Skip to first unread message

Fecker

unread,
Jun 8, 2011, 10:14:43 AM6/8/11
to phonegap
Hi there. I'm using the Phonegap API for the first time in Xcode 4 on
an iPhone 3GS. I've included the phonegap.js file in my index.html
page (it didn't exist in www when I made the project, so I copied it
from WebOS folder in the phonegpa 0.9.5.1 zip) and have run my code.
But nothing happens - even when I tell it to pop an alert during
onLoad(), still nothing happens. It's as if all phonegap calls are
ignored! So I have just tried something simple like below, but still,
nothing happens. Please help!

<script type="text/javascript" src="assets/phonegap.js"></script>
function onLoad() {
navigator.notification.beep(2);
}
<body onload="onLoad()">

Simon MacDonald

unread,
Jun 8, 2011, 10:17:01 AM6/8/11
to phon...@googlegroups.com
You have to wait for the "deviceready" event before you can call any PhoneGap API methods.

Simon Mac Donald
http://hi.im/simonmacdonald


--
You received this message because you are subscribed to the Google
Groups "phonegap" group.
To post to this group, send email to phon...@googlegroups.com
To unsubscribe from this group, send email to
phonegap+u...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/phonegap?hl=en?hl=en

For more info on PhoneGap or to download the code go to www.phonegap.com

Fecker

unread,
Jun 8, 2011, 10:20:26 AM6/8/11
to phonegap
I hasten to add that I have coded it correctly, as below (in case
you've taken the above code example literally!)

<html>
<head>
<script type="text/javascript" src="assets/phonegap.js"></script>
<script type="text/javascript" charset="utf-8">
function onLoad() {
navigator.notification.beep(2);
}
</script>
</head>
<body onload="onLoad()">
</body>
</html>

Fecker

unread,
Jun 8, 2011, 10:22:41 AM6/8/11
to phonegap
Yes, I've tried that initially too. That was simply a basic example -
here is my full javascript code:


function onLoad() {
document.addEventListener("deviceready", onDeviceReady, false);
}


function onDeviceReady() {
navigator.notification.activityStart();
setTimeout(function() {
navigator.network.isReachable("www.google.co.uk",
reachableCallback);
}, 500);

}

function alertDismissed() {

}

function showAlert() {
navigator.notification.alert(
'You are currently offline, so you will not be able to
make a booking.',
alertDismissed,
'MyApp',
'Done'
);
}

function reachableCallback(reachability) {
if (reachability.internetConnectionStatus == 0) {
showAlert();
location.reload(true);
}
else {

setTimeout("showAlert()", 20000);
}

}



On Jun 8, 3:17 pm, Simon MacDonald <simon.macdon...@gmail.com> wrote:
> You have to wait for the "deviceready" event before you can call any
> PhoneGap API methods.
>
> Simon Mac Donaldhttp://hi.im/simonmacdonald

Shazron Abdullah

unread,
Jun 8, 2011, 12:58:22 PM6/8/11
to phon...@googlegroups.com

On 2011-06-08, at 7:14 AM, Fecker wrote:

> it didn't exist in www when I made the project, so I copied it
> from WebOS folder in the phonegpa 0.9.5.1 zip) and have run my code.

There's your problem. Each of the platforms has its own phonegap.js. Run it once to get the phonegap.0.9.5.1 copied in. Try it on a new project and run it once to see what I mean. Reasons why etc http://blogs.nitobi.com/shazron/2011/05/05/phonegap-xcode-4-template/


Todd

unread,
Jun 8, 2011, 1:26:11 PM6/8/11
to phonegap
a minor thing, but just in case it is helpful... should you get it out
of the "iOS" folder for iPhone, not the "webOS" folder? For me I have
to run the project blank the very first time as was just mentioned
above.

Fecker

unread,
Jun 9, 2011, 4:42:17 AM6/9/11
to phonegap
Ahh, that makes sense! I had a dig around and found PhoneGapLib in ~/
Documents so I copied the phonegap.js file from there into my www
folder and it all works perfectly. Many thanks!


On Jun 8, 5:58 pm, Shazron Abdullah <shazron.abdul...@nitobi.com>
wrote:

Fecker

unread,
Jun 9, 2011, 4:43:06 AM6/9/11
to phonegap
Yes, that was my mistake, taking it from webOS folder - but I couldn't
find the iPhone folder. Now I've found it, it works. Thanks.
Reply all
Reply to author
Forward
0 new messages