我正在使用phonegap来检查是否有互联网连接
if(navigator.connection.type !== Connection.NONE){ ..do an ajax call
这在安卓中工作正常,但在 iPhone5 中,当 WiFi 关闭时,我只是得到connection = none
,仅此而已......android至少进入3G并做这个电话。
我做错了什么?我是否必须强制iPhone5使用数据连接,如果是,如何?正如我所说,如果有WiFi连接,两者都可以正常工作。
尝试扫描所有连接
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';
if(states[networkState]=='No network connection'){
alert("no connection");
}
if(states[networkState]=='Cell 3G connection'){
//do something
}
...
...
}
对于检查所有连接,您可以尝试
if(states[networkState]=='No network connection'){
alert("no connection");
}else{
//do something
}