科尔多瓦 iOS 连接对象不起作用


我不知道

它只发生在我身上还是发生在所有人身上;I我使用的是科尔多瓦 3.3 ;与 iOS 7 ;当我使用连接对象时,它不返回任何内容。

function checkConnection() {
alert("a");
var networkState = navigator.Connection.CELL, states = {};
states[Connection.UNKNOWN] = 'Unknown';
states[Connection.ETHERNET] = 'Ethernet';
states[Connection.WIFI] = 'WiFi';
states[Connection.CELL_2G] = '2G';
states[Connection.CELL_3G] = '3G';
states[Connection.CELL_4G] = '4G';
states[Connection.NONE] = 'None';
return states[networkState];
}
var app = {
// Application Constructor
initialize: function() {
    this.bindEvents();
},
// Bind Event Listeners
//
// Bind any events that are required on startup. Common events are:
// 'load', 'deviceready', 'offline', and 'online'.
bindEvents: function() {
    document.addEventListener('deviceready', this.onDeviceReady, false);
},
// deviceready Event Handler
//
// The scope of 'this' is the event. In order to call the 'receivedEvent'
// function, we must explicity call 'app.receivedEvent(...);'
onDeviceReady: function() {
    app.receivedEvent('deviceready');
    alert(checkConnection());
},
// Update DOM on a Received Event
receivedEvent: function(id) {
    var parentElement = document.getElementById(id);
    var listeningElement = parentElement.querySelector('.listening');
    var receivedElement = parentElement.querySelector('.received');
    listeningElement.setAttribute('style', 'display:none;');
    receivedElement.setAttribute('style', 'display:block;');
    console.log('Received Event: ' + id);
    }
    };
问题是设备就绪中的警报工作正常

,但另一部分工作不正常;甚至连接功能中的警报工作正常,但没有返回任何内容。此外,我找不到控制台中显示的控制台消息。我按照电话间隙中的所有步骤进行操作

尝试更改此行:

var networkState = navigator.Connection.CELL, states = {};

var networkState = navigator.connection.type, states = {};

还要将其添加到您的状态对象中:

states[Connection.CELL]     = 'Cell generic connection';

有关iOS的文档声明的是,它无法返回特定的单元连接,因此如果检测到通用单元连接,它将传递通用单元连接。

最新更新