用于检查当前网络连接的标准 PhoneGap API(见下文)似乎没有更新它在 Ripple Emulator 中的结果。当我更改连接类型并执行 checkConnection() 时,它会从第一次调用此函数时返回连接类型(在 deviceready 时)
function checkConnection() { // Checks current network status
networkState = navigator.connection.type;
console.log(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';
// DEBUG: notify on network state
console.log("Connection type: " + states[networkState]);
}
我还需要做些什么(添加事件侦听器?)才能让它工作吗?通常,设备只会在状态从在线变为离线时触发事件,但我需要区分“免费”互联网和 xG 连接。