0

我正在使用 phonegap 检查是否有互联网连接

if(navigator.connection.type !== Connection.NONE){ ..do an ajax call

这在 android 中运行良好,但在 iPhone5 中,当 WiFi 关闭时,我就得到了connection = none,仅此而已......android 至少进入 3G 并进行通话。

我究竟做错了什么?我是否必须强制 iPhone5 使用数据连接,如果是,怎么办?正如我所说,如果有 WiFi 连接,两者都可以正常工作。

4

1 回答 1

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
}
于 2013-10-20T19:25:53.510 回答