当我运行以下代码时,我抓住了Apache Cordova文档,我得到了一个
TypeError: 'undefined' is not an object (evaluating 'navigator.network.connection')
错误。我已经遵循了有关安装/卸载插件的各种说明,但一直迷路。
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 type: ' + states[networkState]);
}
我把它放在配置文件中
<plugin name="NetworkStatus" value="CDVConnection" />
以及
<feature name="NetworkStatus"> <param name="ios-package" value="CDVConnection" />
我尝试在终端和Xcode中构建。
答案 0 :(得分:1)
确保将插件添加到项目中:
$ cordova plugin add org.apache.cordova.network-information
另外,请确保列出插件:
$ cordova plugin ls