how to see phonegap javascript log messages on xco

2019-02-05 15:36发布

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?

10条回答
做自己的国王
2楼-- · 2019-02-05 16:00

In Phonegap 3.0 you have to add a plugin for console.log to work in the xcode console.

$ phonegap local plugin add https://git-wip-us.apache.org/repos/asf/cordova-plugin-console.git

More info: http://docs.phonegap.com/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-02-05 16:06

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)

查看更多
Fickle 薄情
4楼-- · 2019-02-05 16:06
  1. Add the Debug console plugin
  2. Add a console.log message in onDeviceReady in the sample phonegap code or code that runs after that.

Important: console messages are displayed after the 'deviceready' event. Console.log will not generate message before that.

查看更多
来,给爷笑一个
5楼-- · 2019-02-05 16:07

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

查看更多
我命由我不由天
6楼-- · 2019-02-05 16:09
confirm("msg here: "+var);

or

console.log("msg here: "+var);
查看更多
Evening l夕情丶
7楼-- · 2019-02-05 16:10

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.

查看更多
登录 后发表回答