Skip to content Skip to sidebar Skip to footer

Check Internet Connection On IOS App With Cordova Phonegap 3.3.0 Not Working

I have tried following this guide on Cordova docs, but it doesn't seem to work. Here is my code: I have added to config.

Solution 1:

I finally solved the problem!! - by starting all over again from scratch and doing the following:

Command line:

sudo npm install -g cordova
cordova create hello com.example.hello HelloWorld
cd hello
cordova platform add ios
cordova platforms ls //This will list ios
cordova plugin add org.apache.cordova.network-information
cordova build

Then drag my files (HTML, Javascript etc) into the platforms/ios/www/ folder.

Open up hello.xcodeproj in xcode.

Edit config.xml and add the lines:

<feature name="NetworkStatus">
    <param name="ios-package" value="CDVConnection" />
</feature>

Then in my index file I used the JavaScript:

    <script type="text/javascript">
        document.addEventListener("deviceready", onDeviceReady, false);
        // device APIs are available
        function onDeviceReady() {
            if(navigator.network.connection.type == Connection.NONE){
                alert("nocon");
            }else{
                alert("yescon");
            }
        }
    </script>

Then run it in the iPhone / iPad simulator and it will output "yescon" if there is a connection and "nocon" if there isn't!!

Hope this helps!


Solution 2:

This works for me:

if(navigator.network.connection.type == Connection.NONE){
//no connection
}else{
//You are connected.
}

Though I look in the documentation and looks like there's a difference using these lines:

var networkState = navigator.network.connection.type;

navigator.network.connection.type is set to Connection.CELL_2G for all cellular data.

Would it be var networkState = Connection.CELL_2G;?


Post a Comment for "Check Internet Connection On IOS App With Cordova Phonegap 3.3.0 Not Working"