console.log 在 iOS PhoneGap 3.0 应用程序中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19183295/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 02:04:36  来源:igfitidea点击:

console.log not working in an iOS PhoneGap 3.0 app

iosxcodecordova

提问by poiuytrez

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?

我正在将应用程序从 PhoneGap 1.9 升级到 PhoneGap 3.0。console.log() 函数不再工作。以前,输出是在 XCode 控制台中编写的。恢复日志记录功能的最佳方法是什么?

I have read: PhoneGap 2.0 doesn't show console.log in XCodebut in PhoneGap 3.0 console.log does not work even after the deviceReady event.

我读过:PhoneGap 2.0 在 XCode 中不显示 console.log但在 PhoneGap 3.0 console.log 中,即使在 deviceReady 事件之后也不起作用。

I am also interested to see the javascript errors directly in xcode.

我也有兴趣直接在 xcode 中查看 javascript 错误。

回答by Sam Thompson

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:

在更高版本的 phonegap/cordova 中,在您的项目中添加调试控制台插件:

cordova plugin add org.apache.cordova.console

cordova plugin add org.apache.cordova.console

回答by Jonathan Dixon

It turned out, at least in my case, that devicereadyfunction for the logger was not getting called. The final line in logger.js.

结果证明,至少在我的情况下,deviceready记录器的那个函数没有被调用。中的最后一行logger.js

document.addEventListener("deviceready", logger.__onDeviceReady, false);

The solution (or really a work-around) is to call the logger.__onDeviceReadyfunction from your devicereadylistener function:

解决方案(或真正的解决方法)是logger.__onDeviceReady从您的deviceready侦听器函数中调用该函数:

function onDeviceReady() {
    if (window.cordova.logger) {
        window.cordova.logger.__onDeviceReady();
    }
}

document.addEventListener('deviceready', onDeviceReady, false);

回答by Fostah

I've found JSconsole.comextremelyuseful for remotely capturing console logs from mobile devices.

我发现JSconsole.com对于从移动设备远程捕获控制台日志非常有用。

Heres how you set it up:

这是你如何设置它:

  1. In you apps index.html, Include(change the ID):

      <script src="http://jsconsole.com/remote.js?<MAKE UP SOME UNIQUE ID>"></script>
    
  2. On your computer, Go to jsconsole.com and type :listen <YOUR UNIQUE ID>
  1. 在您的应用程序 index.html 中,包含(更改 ID):

      <script src="http://jsconsole.com/remote.js?<MAKE UP SOME UNIQUE ID>"></script>
    
  2. 在您的计算机上,转到 jsconsole.com 并键入 :listen <YOUR UNIQUE ID>

Open your app on your mobile device, you will see console logs on your computer.

在移动设备上打开您的应用程序,您将在计算机上看到控制台日志。

回答by Muhammad Qasim

Add the console plugin as in the Sam's answer and ensure to include cordova.json every page otherwise no plugin works.

在 Sam 的回答中添加控制台插件,并确保在每个页面上都包含 cordova.js,否则没有插件工作。

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.

使用 phonegap 插件时,我在脚本标签中添加了 phonegap.js 然后我注意到插件(任何)仅适用于 index.html 页面。当我将 phonegap.js 更改为 cordova.js 时,插件(通知、相机等)开始在其余页面上工作。如果这对任何人有帮助。

回答by user3051092

If you have installed the Cordova console-plug-in, then when you run your app:

如果您已经安装了 Cordova 控制台插件,那么当您运行您的应用程序时:

phonegap run iOS

you will find the logs at:

您将在以下位置找到日志:

[your project dir]/platforms/ios/cordova/console.log

for IOS. All console logs show up as expected.

对于 IOS。所有控制台日志都按预期显示。

回答by Omnicon

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:

通过命令行界面将控制台插件添加到ios平台时(或重新安装后)出现以下或类似的错误信息:

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

“CDVPlugin 类 CDVLogger (pluginName: Console) 不存在。”

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.

打开您的 Xcode 项目并转到“构建阶段”选项卡。现在打开名为“编译源”的下拉菜单。单击列表末尾的“+”号并添加“CDVLogger.m”或任何其他缺少的源。

回答by Gerold Meisinger

Besides adding the Console plugin I have another assumption why it might not work:

除了添加控制台插件之外,我还有另一个假设,为什么它可能不起作用:

console.log in Phonegap is called asynchronously thus if a future call fails, the whole function fails and all log calls within are swallowed.

Phonegap 中的 console.log 是异步调用的,因此如果未来的调用失败,整个函数就会失败,并且其中的所有日志调用都会被吞掉。

  receivedEvent = function( id ) {
    alert( 'This message is displayed because alert is called synchronously ')
    console.log( 'This will not be displayed in Phonegap only in browser' )
    callingAFunctionWhichDoesNotExist()
    console.log( 'This will neither be displayed in Phonegap nor in browser' )
  }

回答by Gobi Dasu

I found GapDebugreally useful. Unlike anything else [cough cough weinre], it let's you console log from your local app

我发现GapDebug真的很有用。不像其他任何东西 [咳嗽咳咳],它让你从本地应用程序控制台日志