Last active
November 21, 2016 09:46
-
-
Save rubinchyk/07064dee40ae7954c1a343a2faecb071 to your computer and use it in GitHub Desktop.
Ionic1: Checking internet connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Checking internet connection | |
// Install "cordova plugin add cordova-plugin-network-information" | |
// 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'; | |
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(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment