In one of my Ionic application, I need to check Network connection is available or not on the Device. If not I need to display an alert that, "Network connection is not available". So I've installed the Cordova's network connection plugin and used the following code. But the Offline event is firing twice I think. Because the alert message is displaying twice, while the app is in Offline mode.
.run(function($ionicPlatform, $ionicPopup) {
$ionicPlatform.ready(function() {
document.addEventListener("offline", displayofflineAlert, false);
function displayofflineAlert() {
$ionicPopup.alert({
title: "No Internet",
content: "No Internet Connection available."
})
.then(function(result) {
ionic.Platform.exitApp();
});
}
});
})
Not sure why it is firing twice. I need it to fire once.