Skip to content

Instantly share code, notes, and snippets.

@EddyVerbruggen
Created April 11, 2014 20:33
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EddyVerbruggen/10499328 to your computer and use it in GitHub Desktop.
Save EddyVerbruggen/10499328 to your computer and use it in GitHub Desktop.
Check for a WiFi connection in a PhoneGap app and show a message if it's not available - and stop checking
"use strict";
(function() {
var intervalID = null;
function startCheckingNetworkConnection() {
intervalID = setInterval(function() {
var networkState = navigator.connection.type;
var isWifi = networkState == Connection.WIFI;
var isUnknown = networkState == Connection.UNKNOWN;
if (!isWifi && !isUnknown) {
clearInterval(intervalID);
// https://github.com/EddyVerbruggen/Toast-PhoneGap-Plugin
window.plugins.toast.showLongBottom("You're not on WiFi, this may be costly!");
}
}, 5000);
}
document.addEventListener('deviceready', startCheckingNetworkConnection, false);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment