我正在使用 cordova 和 ionic 框架开发 android 应用程序,使用来自 这里(https://github.com/apache/cordova-plugin-network-information)。但是设备就绪警报触发,然后出现以下错误。
"TypeError: Cannot read property 'type' of undefined
这是导航器对象
navigator.connection.type
我会在下一行中得到错误。
最佳答案
用我的
document.addEventListener("deviceready", onDeviceReady, false);
// Cordova is ready
function onDeviceReady() {
checkConnection()
}
function checkConnection() {
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.CELL] = 'Cell generic connection';
states[Connection.NONE] = 'No network connection';
alert('Connection type: ' + states[networkState]);
}
关于javascript - 无法读取 cordova 网络插件中未定义错误的属性 'type',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26458781/