Skip to content

Instantly share code, notes, and snippets.

@rubinchyk
Last active November 21, 2016 09:46
Show Gist options
  • Save rubinchyk/07064dee40ae7954c1a343a2faecb071 to your computer and use it in GitHub Desktop.
Save rubinchyk/07064dee40ae7954c1a343a2faecb071 to your computer and use it in GitHub Desktop.
Ionic1: Checking internet connection
// 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