0

I keep reading that the console.log needs to come after the onDeviceReady function, but I don't see any onDeviceReady functions in the cordova.js. Do I need to write my own? Does anybody know what the function would look like? What if I just wanted to console log "hello"?

Also, I noticed that cordova.js is not included as a script in the index.html. I'm assuming it needs to be if I want to see anything logged in the xcode console?

LeftyX
  • 35,328
  • 21
  • 132
  • 193
user3294779
  • 593
  • 2
  • 7
  • 23
  • 1
    possible duplicate of [how to see phonegap javascript log messages on xcode console](http://stackoverflow.com/questions/13357568/how-to-see-phonegap-javascript-log-messages-on-xcode-console) – Jonathan Hall Aug 19 '15 at 02:07

1 Answers1

2

If you create the phonegap project by command line interface as described in their site

You should include cordova-3.x.x.js in your html head.

<head>
<script type="text/javascript" src="cordova-3.x.x.js"></script>
<script>
  function onLoad() {
   document.addEventListener(
  'deviceready', onDeviceReady, false);
}
function onDeviceReady() {
  // do Something!
  // example: display a Cordova Console
  // see docs.phonegap.com for full details
  console.log("HELLO...");
}
</script>
</head>
<body onload="onLoad();">

Inorder to use the debug console in phonegap, you should add the plugin to the project by CLI

Type this command in Terminal

$ cordova plugin add org.apache.cordova.console
jeprubio
  • 17,312
  • 5
  • 45
  • 56
manukv
  • 2,031
  • 18
  • 30
  • Sorry this is my first time using xcode, and maybe I'm not looking in the right place, but where is the console? I see the outputs at the bottom right of my screen and the debug in the log navigator, but I don't see the console log anywhere. Where should I be looking? – user3294779 Apr 09 '14 at 04:45
  • did you add the console plugin? – manukv Apr 09 '14 at 04:53
  • Yes I included it. I actually included it before the first build because I heard there was a bug. I did it again just for good measure and got Plugin "org.apache.cordova.console" already installed on ios. – user3294779 Apr 09 '14 at 05:01
  • 1
    where in the directory is cordova-3.x.x.js located? I only see cordova.js in the staging directory. – user3294779 Apr 09 '14 at 05:07
  • Can I console log something inside a js file and see if that works? – user3294779 Apr 09 '14 at 05:13
  • 1
    I don't understand why your example doesn't work. I saw the exact same example in the phonegap docs. The only way I can get anything to log in the console is if I add something to the onDeviceReady: function() that's inside the index.js, but I don't understand where that function is being called? If I name a function that console logs, and then place it inside " document.addEventListener("deviceready", FUNCTION_HERE, false); ", it still does not work. I got most things working in the ripple emulator but now the ios simulator/xcode is throwing me through a total loop. – user3294779 Apr 28 '14 at 00:54
  • the cordova console plugin should no longer be included in your apps as the code was included in cordova-ios 4.5.0 and newer versions – jeprubio Mar 07 '18 at 08:51