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.NONE] = 'No network connection';
alert(Connection.WIFI);
alert(navigator.connection.type);
alert('Connection type: ' + states[networkState]);
}
答案 0 :(得分:6)
您是否在deviceReady
事件后调用了checkConnection?
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
checkConnection();
}
在checkConnection中使用navigator.network.connection.type
代替navigator.connection.type
,因为https://issues.apache.org/jira/browse/CB-1807
答案 1 :(得分:5)
这似乎是cordova 2.2.0中的一个错误