Finding work on the Internet or not in Jordan Cordoba

I want to show a message when the Internet does not work in the cordon Ion application, can anyone do this in the Ionic Cordova application.

+4
source share
5 answers

To obtain information about the network from the device, there is a network information plugin . Add

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

include it in app.js and register a standalone event handler from the event handler onDeviceReady,

onDeviceReady: function() {
    document.addEventListener("offline", onOffline, false);
},

onOffline: function () {
  //handle offline 
}
+6
source

This is actually quite simple. Add a plugin:

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

index.html. $cordovaNetwork , . .

document.addEventListener("deviceready", function () {
 // Check for network connection
    if(window.Connection) {
    //you can log your connection as well, whether it is internet, wifi and so on.In this case you are checking for no connection
alert(navigator.connection.type);
      if(navigator.connection.type == Connection.NONE) {
        $ionicPopup.confirm({
          title: 'Network Problem',
          content: 'Sorry, Please Check Your Network Connection.'
        })
//or you can simply navigate it to a page with the no internet connection html.
      }
    }
})

// . , . $cordovaNetwork, $ionicPlatform .

var type = $cordovaNetwork.getNetwork();

   var isOnline = $cordovaNetwork.isOnline();

    var isOffline = $cordovaNetwork.isOffline();

 $rootScope.$on('$cordovaNetwork:online', function(event, networkState){
      var onlineState = networkState;
      alert(onlineState);
    })

 $rootScope.$on('$cordovaNetwork:offline', function(event, networkState){
      var offlineState = networkState;
       alert(offlineState);
    })

 document.addEventListener("deviceready", function () {

  $rootScope.$on('$cordovaNetwork:online',function(event,networkState){
    $location.path('/japp/login');
  })

 $rootScope.$on('$cordovaNetwork:offline',function(event,networkState){
     $ionicPopup.confirm({
                        title: "Internet Disconnected",
                        content: "The internet is disconnected on your device."
                    }).then(function(){
                                    ionic.Platform.exitApp();
                    })
  })

, - .

+1

: http://forum.ionicframework.com/t/how-to-check-network-coneection/15806/14

, . ngCordova - :

$rootScope.$on('$cordovaNetwork:online', function() {});
$rootScope.$on('$cordovaNetwork:offline', function() {});
0

( cordova org.apache.cordova.network-information), app.js

if(window.Connection) {
  console.log("checking connection");
    if(navigator.connection.type == Connection.NONE) {
      $ionicPopup.alert({
        title: "No Internet Connection",
        content: "Internet Connection is not available. In offline you can see previously fetched data.",
        okType:"balanced",
      })
      .then(function(result) {
          if(!result) {
            console.log('ok clicked');
          }
      });
    }
}
0

Hi, there is another problem here. Network information only tells you that there is a connection. But this does not mean that you have a connection to a website and / or a working database. In most cases, the application depends on the website and / or database. Therefore, you should also check them out.

-1
source

All Articles