出於某種原因,PhoneGap的連接API返回null
navigator.network.connection.type返回null而不是Connection.NONE
function checkConnection() {
var networkState = navigator.network.connection.type;
alert(networkState);
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';
document.getElementById('connections').innerHTML = states[networkState];
}
我跑從onDeviceReady
功能的設備運行時被調用此功能。
當一切都關閉時,我得到null
。我不應該得到Connection.NONE
而不是null
?這真的很煩人,因爲我無法檢查手機是否連接。它在Wifi打開時工作正常。
嘿,我讀過它不應該再回到零的代碼。這個bug的複製場景是什麼?我已將手機置於飛行模式並正確返回「無」。在調用checkConnection()之前,您是否確保等待「deviceready」事件? –