簡體   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