Überprüfen Sie die internet-Verbindung auf iOS-app mit Cordova, Phonegap 3.3.0 funktioniert nicht

Ich haben versucht folgenden diese guide auf Cordova docs, aber es scheint nicht zu funktionieren.

Hier ist mein code:

Habe ich Hinzugefügt <plugin name="NetworkStatus" value="CDVConnection" /> zu config.xml.

und das Skript zu meiner index.html:

    <script type="text/javascript">


        document.addEventListener("deviceready", onDeviceReady, false);

        //device APIs are available
        //
        function onDeviceReady() {
            alert("1"); //runs this alert
            checkConnection();
        }

        function checkConnection() {
            var networkState = Connection.CELL;
            alert("2"); //doesn't run this

            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]);
        }

    </script>

var networkState = Connection.CELL; scheint das problem verursachen, da Sie nicht führen Sie die folgende Warnung, ich habe auch versucht navigator.connection.type aber das gleiche passierte.

Wenn ich die app starte in Chrome die Konsole gibt folgenden Fehler:

Uncaught ReferenceError: Connection is not defined 

Jemand weiß, wie dieses problem zu lösen?

Cheers

  • Haben Sie enthalten Cordova.js in Ihrem index.html Datei
  • Ja, ich habe <script type="text/javascript" src="cordova.js"></script>
InformationsquelleAutor smj2393 | 2013-12-19
Schreibe einen Kommentar