Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

deviceready handler not being called ios phonegap 3.3.3

index.html

<script>
   function onDeviceReady() {
       alert("onDeviceReady");
       var options = {frequency: 500};
       watchId = navigator.accelerometer.watchAcceleration(onSuccess, onFailure, options);
    }
    document.addEventListener("deviceready", onDeviceReady, false);
</script>

Phonegap 3.3.3 device ready handler is not being called.

like image 894
user812954 Avatar asked Jan 03 '14 19:01

user812954


2 Answers

Make sure you have included the phonegap.js (or cordova.js) script in your html. Otherwise your code is fine. Try commenting everything else except the alert in onDeviceReady() in case the issue still persists.

Try posting your index.html with the question if there are still issues.

like image 117
Shah Abaz Khan Avatar answered Nov 09 '22 18:11

Shah Abaz Khan


It is a best practice to set your event listener in a function after the document finishes loading. Try something like this:

<body onload="onLoad()">

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

or with jquery:

$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, false);
});
like image 25
Dawson Loudon Avatar answered Nov 09 '22 16:11

Dawson Loudon