0
我無法檢查連接狀態。我已經成功添加插件org.apache.facebook.networkinformation
。但是我仍然有錯誤。無法讀取未定義的屬性「連接」。在科爾多瓦3.2.0
<script type="text/javascript" src="cordova.js"></script>
<script src="js/Connection.js"></script>
<script src="js/network.js"></script>
<script type="text/javascript" charset="utf-8">
document.addEventListener("deviceready", onDeviceReady(), false);
function onDeviceReady() {
alert(navigator.network.connection.type);
alert(1);
}
function checkConnection() {
alert(navigator.network.connection.type);
var networkConnectionType = navigator.network.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.NONE] = 'No network connection';
alert('Connection Type: ' + states[networkConnectionType]);
}
</script>
雅工作的按鈕點擊,但爲什麼不能在設備上準備就緒。 – user2021740 2014-09-02 06:55:48
我在onDeviceReady()中調用checkConnection()。但它不工作? – user2021740 2014-09-02 06:57:54
你必須以另一種方式來做,我會告訴你只需5分鐘,並編輯我的答案;-) – Sithys 2014-09-02 07:05:17