为什么没有被检测到的网络连接的变化

为什么没有被检测到的网络连接的变化

本文介绍了为什么没有被检测到的网络连接的变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图来显示和警报,当连接状态的变化,但我的code在所有(以下提醒没有被执行)并没有影响

I am trying to show and alert when the connection status changes but my code has not effect at all (alert below is not being executed).

下面是:

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');

        document.addEventListener("online", onOnline, false);
        document.addEventListener("offline", onOffline, false);
    },
    // 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);
    }


};

function onOffline() {
    alert("on");
}

function onOffline() {
    alert("off");
}

我的PhoneGap的版本是3.3.0-0.18.0。所以我生成我瞄准Android的项目是这样的:

My PhoneGap version is 3.3.0-0.18.0. I am targeting Android so I generated the project like this:

phonegap create my-app
cd my-app
phonegap run android

我所缺少的?

推荐答案

由于3.0版本,您不必手动添加权限AndroidManifest.xml中。
在页面http://docs.phonegap.com/en/3.3.0/cordova_connection_connection.md.html#Connection你可以阅读:

Since version 3.0 you don't have to manually add permissions to AndroidManifest.xml.On page http://docs.phonegap.com/en/3.3.0/cordova_connection_connection.md.html#Connection you can read:

由于3.0版本,科尔多瓦实现了设备级别的API插件。使用CLI的插件命令,在命令行界面描述,添加或删除此功能项目:

As of version 3.0, Cordova implements device-level APIs as plugins. Use the CLI's plugin command, described in The Command-Line Interface, to add or remove this feature for a project:

$ cordova plugin add org.apache.cordova.network-information


如果你不使用可以使用的代替PhoneGap的(这是建立在科尔多瓦的顶部)。


If you don't use the phonegap build service you can use cordova instead of phonegap (which is built on top of cordova).

希望这有助于。

这篇关于为什么没有被检测到的网络连接的变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 22:00