繁体   English   中英

如何在混合应用程序中调试onDeviceReady — Cordova

[英]How to debug onDeviceReady in a hybrid app — cordova

请我有我的反应应用程序混合应用程序,我要添加科尔多瓦框架。 我添加了cordova项目,build,release,都在模拟器上成功模拟了我的应用程序。 cordova项目在我的应用程序中添加了index.js,我在下面的index.html中引用了它。

</head>

<body>

<div id="root" class="root app">
    <div class="mobile-page">
        <img class="spinner" src="img/symbol-logo.svg" />
    </div>
</div>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="index.js"></script>
<script src="boot.js"></script>
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=fetch,Promise,Array.from,Array.prototype.find,Array.prototype.includes,String.prototype.startsWith,String.prototype.includes,Math.sign,Intl.~locale.en,Intl.~locale.id,Intl.~locale.ru,Intl.~locale.fr&unknown=polyfill"></script>
<script async src="app.js"></script>

上面的app.js是使用webpack构建的,而我的应用是使用react js开发的。 我上面的index.js

var app = {
    initialize: function() {
        this.bindEvents();
    },
    bindEvents: function() {
        document.addEventListener('deviceready', this.onDeviceReady, false);
        document.addEventListener('resume', this.onDeviceResume, false);
    },

'receivedEvent'
    onDeviceReady: function() {
        app.receivedEvent('deviceready');
        codePush.sync();
    },

    onDeviceResume: function () {
        app.receivedEvent('resume');
        codePush.sync();
    },

    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    },
};

app.initialize();

我的问题是,我不确定我的index.js事件是否被调用。 我想测试/调试上面的onDeviceReady事件。 我希望不能打印简单的控制台消息并进行调试。 请我怎么做?

我通常使用cordova浏览器平台。

cordova platform add browser

然后在浏览器中构建您的应用

cordova platform build browser

cordova emulate browser

您的cordova将在本地主机上午餐,您可以在其中看到控制台消息。 如果您也按照上面的用户提示设置了断点。 那就是我的方式。 希望能帮助到你。

您也可以尝试phonegap桌面应用程序。

它的确非常简单,只需在其中包含您的项目文件,然后输入本地URL,即可将其提供给您的移动设备上的开发者应用。

Phonegap桌面应用程序具有一个控制台,可帮助您查看日志,因此您可以简单地调试应用程序。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM