No out of the box device and no console.log with xcode using cordova 1.5

This is all the code I have and I don't get any logs in xcode or deviceReady events (which I also don't get on any other platform. On Ubuntu + Android + Eclipse I get console logs, but not the device in chrome)

Js / cordova-1.5.0.js exists and is loading as indicated by the warning statement I entered there. Any clues where should I look? Thanks in advance;)

<div id="d"></div>
    function foo() {console.log('test'); document.getElementById('d').innerHTML += 'called';}
    window.setTimeout(foo, 5000);
    window.setTimeout(foo, 15000);
    window.setTimeout(foo, 25000);
    window.setTimeout(foo, 35000);
    console.log('non timed console.log');

<script src="js/cordova-1.5.0.js"></script>
    document.addEventListener("deviceready", onDeviceReady, false);

    function onDeviceReady() {
        //somewhy this never happens



Screenshot form xcode


source to share

3 answers

  • Console.log only works after deviceReady event

  • Phonegap uses different phonegap.js files for android and ios, and only Android one comes with a downloadable archive. Read Dhawal's Commentary to find out where to get the ios version.

  • I used Weinre for debugging and almost missed that it overrides console.log method so console.log doesn't work with weinre



As Alex pointed out, console.log is not available until your PhoneGap device is ready. By calling this too quickly, you are throwing a comparison error.

Remove ALL existing javascript and try this instead (replacing the warning on the second line with your own code):

var app = {
    // denotes whether we are within a mobile device (otherwise we're in a browser)
    iAmPhoneGap: false,
    // how long should we wait for PhoneGap to say the device is ready.
    howPatientAreWe: 10000,
    // id of the 'too_impatient' timeout
    timeoutID: null,
    // id of the 'impatience_remaining' interval reporting.
    impatienceProgressIntervalID: null,

    // Application Constructor
    initialize: function() {
    // Bind Event Listeners
    // Bind any events that are required on startup. Common events are:
    // `load`, `deviceready`, `offline`, and `online`.
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
        // after 10 seconds, if we still think we're NOT phonegap, give up.
        app.timeoutID = window.setTimeout(function(appReference) {
            if (!app.iAmPhoneGap) // jeepers, this has taken too long.
                // manually trigger (fudge) the receivedEvent() method.   
        }, howPatientAreWe, this);
        // keep us updated on the console about how much longer to wait.
        app.impatienceProgressIntervalID = window.setInterval(function areWeThereYet() {
                if (typeof areWeThereYet.howLongLeft == "undefined") { 
                    areWeThereYet.howLongLeft = app.howPatientAreWe; // create a static variable
                areWeThereYet.howLongLeft -= 1000; // not so much longer to wait.

                console.log("areWeThereYet: Will give PhoneGap another " + areWeThereYet.howLongLeft + "ms");
            }, 1000);
    // deviceready Event Handler
    // The scope of `this` is the event. In order to call the `receivedEvent`
    // function, we must explicity call `app.receivedEvent(...);`
    onDeviceReady: function() {
        app.iAmPhoneGap = true; // We have a device.

        // clear the 'too_impatient' timeout .
    // Update DOM on a Received Event
    receivedEvent: function(id) {
        // clear the "areWeThereYet" reporting.
        console.log('Received Event: ' + id);
        myCustomJS(app.iAmPhoneGap); // run my application.


function myCustomJS(trueIfIAmPhoneGap) {
    // put your custom javascript here.
    alert("I am "+ (trueIfIAmPhoneGap?"PhoneGap":"a Browser"));




I know the question was asked 9 months before, but I stumbled upon the same issue.

If you want debug messages to be displayed in the console weinre

, you have to call:



after deviceready



You seem to need luck to get console messages in weinre

- thats bad :(



All Articles