how to see phonegap javascript log messages on xcode console

佐手、 提交于 2019-12-30 02:36:12

问题


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?


回答1:


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




回答2:


  1. On your real iDevice or in iOS simulator go to Settings > Safari > Advanced and turn on Web Inspector.
  2. Desktop Safari: Safari > Preferences > Advanced and select the Show develop menu in menu bar checkbox.
  3. Now that you have either iOS Simulator open or your iDevice connected to your mac start using web inspector on your website: On your mac, open Safari and go to Develop



回答3:


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




回答4:


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)




回答5:


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.




回答6:


In later versions of phonegap/cordova, to add the debug console plugin in your project:

cordova plugin add org.apache.cordova.console




回答7:


confirm("msg here: "+var);

or

console.log("msg here: "+var);



回答8:


In my case, i just needed to comment the following lines in the cordova.js :

if(typeof window.console === "undefined") { window.console = { log:function(){} };




回答9:


  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.




回答10:


Problem

The following or a similar error message occurs when adding the console plugin to the ios platform (or after reinstalling) via Command-line Interface:

"CDVPlugin class CDVLogger (pluginName: Console) does not exist."

Solution

Open your Xcode project and go to the tab "Build Phases". Now open the drop-down named "Compile Sources". Click on the "+" sign at the end of the list and add "CDVLogger.m" or any other missing source.



来源:https://stackoverflow.com/questions/13357568/how-to-see-phonegap-javascript-log-messages-on-xcode-console

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!