Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cordova DeviceReady not firing

Tags:

I've been banging my head on this one for a few days. After getting a number of "object not defined" errors when trying to create a new FileTransfer() object, it looks like the problem is more basic -- somehow the DeviceReady event is not firing.

Stack Overflow has a lot of hits on this issue, but most of them have to do with pre-3.x cordova builds that had a different architecture (I'm on 4.1.2). I've tried the suggestions in the newer topics I could find -- removing and adding plugins, updating cordova, etc. -- to no avail. To try to isolate the issue, I've commented out the startup code to just a few lines:

Index.html:

<!DOCTYPE html> <html> <head>   <title>Blah</title>   <meta charset="utf-8"/>   <meta name="viewport" content="initial-scale=1, user-scalable=no, minimum-scale=1, maximum-scale=1">   <link href="res/topcoat/css/topcoat-mobile-light.min.css" rel="stylesheet">   <link href="res/css/styles.css" rel="stylesheet">   <link href="res/css/pageslider.css" rel="stylesheet">   <script data-main="js/main" src="lib/require.js"></script> </head> 

Main.js:

require(["app/Application"], function (Application) {   "use strict";    document.addEventListener("deviceready", function(){       $('body').html("<p>device is ready</p>");   },true);    $('body').html("<p>waiting...</p>"); }); 

Instead of displaying "device is ready" in the body after a bit, the screen just displays "waiting...". This happens on both the iOS emulator and the browser (cordova emulate browser).

Cordova info:

$ cordova -v 4.1.2 

Plugin info:

$ cordova plugins org.apache.cordova.globalization 0.3.3 "Globalization" 

(I get the same results if Globalization isn't there).

Is there some other place I should be looking? I'm running from the command line, if that makes a difference.

like image 925
eb1 Avatar asked Jan 09 '15 16:01

eb1


2 Answers

I think in this case you need to include cordova.js in your application, because I don't see cordova.js in your example

<script src="cordova.js"></script> 

Note: path to cordova.js depends on where it located in your app

like image 55
Oleksandr T. Avatar answered Sep 24 '22 12:09

Oleksandr T.


That did not initially fix it for me until I removed

< meta http-equiv="Content-Security-Policy" content=".." / > 
like image 36
A. Soufi Avatar answered Sep 23 '22 12:09

A. Soufi