Skip to content

Instantly share code, notes, and snippets.

@shouse
Created September 4, 2014 17:53
Show Gist options
  • Save shouse/159d5129be009dc9fc8c to your computer and use it in GitHub Desktop.
Save shouse/159d5129be009dc9fc8c to your computer and use it in GitHub Desktop.
Titanium: Find out if device is online
/**
* Find out if Titanium device is online. Doing it this way because of false positives using Ti.Network.online
* @method isOnline
*/
function isOnline() {
var onlineStatus = false;
if (Titanium.Network.networkType === Titanium.Network.NETWORK_NONE) {
onlineStatus = true;
Ti.API.info("Network Status: online");
} else {
onlineStatus = false;
Ti.API.info("Network Status: offline");
}
return onlineStatus;
}
// Invoke it
if (isOnline()) {
// Online code
} else {
// Offline code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment