我正在使用phonegap检查是否有互联网连接
if(navigator.connection.type !== Connection.NONE){ ..do an ajax call
这在android中运行良好,但在iPhone5中,当WiFi关闭时,我得到connection = none
就是这样...... android至少会进入3G并进行通话。
我做错了什么? 我是否必须强制iPhone5使用数据连接,如果是这样的话? 正如我所说,如果有WiFi连接,两者都可以正常工作。
答案 0 :(得分:0)
尝试扫描所有连接
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
}