I am upgrading an app from PhoneGap 1.9 to PhoneGap 3.0. The console.log() function is not working anymore. Previously, the ouput was written in the XCode console. What's the best way to restore the logging feature?
I have read: PhoneGap 2.0 doesn't show console.log in XCode but in PhoneGap 3.0 console.log does not work even after the deviceReady event.
I am also interested to see the javascript errors directly in xcode.
You need the debug console plugin added to your project:
phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git
In later versions of phonegap/cordova, to add the debug console plugin in your project:
cordova plugin add org.apache.cordova.console
It turned out, at least in my case, that deviceready
function for the logger was not getting called. The final line in logger.js
.
document.addEventListener("deviceready", logger.__onDeviceReady, false);
The solution (or really a work-around) is to call the logger.__onDeviceReady
function from your deviceready
listener function:
function onDeviceReady() {
if (window.cordova.logger) {
window.cordova.logger.__onDeviceReady();
}
}
document.addEventListener('deviceready', onDeviceReady, false);
I've found JSconsole.com extremely useful for remotely capturing console logs from mobile devices.
Heres how you set it up:
In you apps index.html, Include(change the ID):
<script src="http://jsconsole.com/remote.js?<MAKE UP SOME UNIQUE ID>"></script>
:listen <YOUR UNIQUE ID>
Open your app on your mobile device, you will see console logs on your computer.
Add the console plugin as in the Sam's answer and ensure to include cordova.js on every page otherwise no plugin works.
When using phonegap plugins I was adding phonegap.js in script tag then I noticed that plugins (any) works on index.html page only. When I changed phonegap.js to cordova.js, plugins(notification, camera etc) started working on rest of the pages. If this helps anyone.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With