I am trying to develop a basic hello world application with phonegap on Xcode. But i can not see the log messages on Xcode console. I have tried console.log and debug.log but they did not worked for me?
How can i see javascript log messages on xcode console?
In Phonegap 3.0 you have to add a plugin for console.log to work in the xcode console.
More info: http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface
console.log("msg here: "+var);
should work. It will come out as...[INFO] msg here: hi!
(after the date, time, app, etc.).To view the messages go to View > Debug Area > Activate Console (or shift+cmd+C)
Important: console messages are displayed after the 'deviceready' event. Console.log will not generate message before that.
Phonegap has a pretty good blog post about this here.
One of the things they mention includes JSLint which I personally use a decent amount. You just post your JS code there and it'll scan for errors and good styling. I also suggest trying to put t the code in a simple html file and run it on the browser. Anything that might seem phone-related, just get rid of it. Its nice to sandbox your javascript on the browser side and then use things like Firebug or Chrome's debugger. (Also I'm sure
console.log()
will work there :D)I've also seen a lot of people mention, including in the blog post, about Weinre so that is something worth checking out.
Other relevant questions that might help:
Phonegap - Javascript debugging in Xcode
iOS PhoneGap debug Workflow
How to see the javascript errors of PhoneGap app in Xcode?
Hope this helps.
EDIT: Found this recently: Debugging in Phonegap
or
As @NickBreen said, you must add the right plugin, but we also needed to wait for the
deviceready
event to fire before the console displayed log statements.