Created
April 11, 2014 20:33
-
-
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
This file contains hidden or 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
"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