有线电视上的互联网检测5.1.1

时间:2015-08-06 21:41:29

标签: javascript cordova

我使用的是phonegap 2.5.0,只是迁移到了cordova 5.1.1。在2.5.0中,我使用以下脚本来检查互联网连接

<script type="text/javascript" src="cordova-2.5.0.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for PhoneGap to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // PhoneGap is loaded and it is now safe to make calls PhoneGap methods
    //
    function onDeviceReady() {
        checkConnection();
    }

    function checkConnection() {
        var networkState = navigator.network.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';

        if ((states[networkState]) == states[Connection.NONE])

        $('#notification').fadeIn("slow", function(){
            $("#notification").fadeOut(7000);
        });



    }

    </script>

但是当我迁移到5.1.1时,脚本无法正常工作。虽然我已将<script type="text/javascript" src="cordova-2.5.0.js"></script>替换为<script type="text/javascript" src="cordova.js"></script>,但我的根文件夹中有cordova.js,这是www

1 个答案:

答案 0 :(得分:0)

我建议使用该插件,请阅读:https://github.com/EddyVerbruggen/SocialSharing-PhoneGap-Plugin

要添加插件,请使用:

cordova plugin add nl.x-services.plugins.socialsharing