gpt4 book ai didi

javascript - 检查与 Cordova 的互联网连接是否无法正常工作

转载 作者:行者123 更新时间:2023-11-29 12:20:35 28 4
gpt4 key购买 nike

我正在使用这个插件来查看我的手机是否有互联网连接: https://github.com/apache/cordova-plugin-network-information

但不工作.. 告诉我这个错误:


D/CordovaLog(3169):文件:///android_asset/www/index.html:第 44 行:未捕获的类型错误:无法读取未定义的属性“连接”

我的功能:

````变种应用= {

//Application Constructor
init: function() {
this.bindEvents();
},

//Bind Event Listeners
bindEvents: function() {
document.addEventListener('deviceready', this.onDeviceReady, false);
},

//Event Handle
onDeviceReady: function() {
//Fast click
FastClick.attach(document.body);

Usuario.verificarOnline();
DataBase.init();

alert(App._internet());
},

getUrl: function(){
return App.url;
},

//verificar conexao com internet
_internet: function(){
var networkState = navigator.network.connection.type;

var states = {};
states[Connection.UNKNOWN] = false;
states[Connection.ETHERNET] = true;
states[Connection.WIFI] = true;
states[Connection.CELL_2G] = true;
states[Connection.CELL_3G] = true;
states[Connection.CELL_4G] = true;
states[Connection.CELL] = true;
states[Connection.NONE] = false;

return states[networkState];
}

};

````

最佳答案

要么是你没有安装插件:

cordova plugin add cordova-plugin-network-information

或者这意味着您在调用函数之前没有等待设备准备就绪:

document.addEventListener('deviceready', function()
{
// Call the function
}

关于javascript - 检查与 Cordova 的互联网连接是否无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30768703/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com