2017-08-02 107 views
0

我正在用visual studio和Cordova創建一個Android APP。 我增加了對netword信息 enter image description here 插件,並從文檔我發現這裏添加的代碼:https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-network-information/ enter image description here 但是當我運行該項目,其回報,我還能做什麼的不確定 錯誤?visual studio cordova,uncaught typeError,無法讀取undefined的屬性

+0

我做了一個基本的演示,但沒有轉載問題。你可以在一個空白的空白項目中試試嗎? –

回答

0

不是將checkConnection函數放在index.html中,而是將它添加到onDeviceReady中的index.js中。

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

    function onDeviceReady() { 
     checkConnection(); 
    }; 

function checkConnection(){ 
    var networkState = navigator.connection.type; 
    var states = {}; 
    states[Connection.UNKNOWN] = 'Unknown connection'; 
    states[Connection.ETHERNET] = 'Ethernet connection'; 
    states[Connection.WIFI] = 'WiFi connection'; 
    states[Connection.CELL_2G] = 'Cell 2G connection'; 
    states[Connection.CELL_3G] = 'Cell 3G connection'; 
    states[Connection.CELL_4G] = 'Cell 4G connection'; 
    states[Connection.CELL] = 'Cell generic connection'; 
    states[Connection.NONE] = 'No network connection'; 

    alert(states[networkState]); 

} 

這應該有效。

相關問題