0

I have installed cordova-plugin-network-information using CLI for a ionic project. I could see the plugin is referred in android.json file in root folder of project and also in cordova_plugin.js in android platform folder.

cordova_plugin.js:

{
        "id": "cordova-plugin-network-information.network",
        "file": "plugins/cordova-plugin-network-information/www/network.js",
        "pluginId": "cordova-plugin-network-information",
        "clobbers": [
            "navigator.connection",
            "navigator.network.connection"
        ]
    }

android.json:

"cordova-plugin-network-information": {
            "PACKAGE_NAME": "com.ionicframework.fts1243245"
        }

I tried calling window.Connection in ionic ready as:

$ionicPlatform.ready(function() {
      if(window.Connection){
          if(navigator.connection.type == Connection.NONE){
              $ionicPopup.confirm({
                  title:"Internet Disconnected",
                  content:"The internet is disconnected on your device."
              })
              .then(function(result){
                  if(!result){
                     ionic.Platform.exitApp();
                  }else{
                      ionic.Platform.exitApp();
                  }
              });
          }
      }
}

But, window.Connection return undefined

Can anyone please let me know what went wrong?

user3382203
  • 169
  • 1
  • 6
  • 25
Selva
  • 123
  • 1
  • 1
  • 12

1 Answers1

0

See

This answer

Which shows that $ionicPlatform.ready can run before Cordova's onDeviceReady() which would perfectly explain what you are seeing - this answer provides some options to mitigate this. The simplest to my mind would seem to be to run the exit code from onDeviceReady() (if you can safely assume that it will fire after $ionicPlatform.ready).

If you don't feel happy assuming it then:

  1. move all of the preparatory code that you are running in $ionicPlatform.ready into a standalone function.
  2. set flags in $ionicPlatform.ready() and onDeviceReady() and check at the end of each to see if both have been set and then run the preparatory function
MStoner
  • 730
  • 4
  • 10
  • Thanks for your reply i'll check and update you, Actully I have used this same code in my previous app everything worked fine, i haven't used deviceRedy() previously – Selva Jun 01 '17 at 10:13