Created
September 4, 2014 17:53
-
-
Save shouse/159d5129be009dc9fc8c to your computer and use it in GitHub Desktop.
Titanium: Find out if device is online
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
/** | |
* 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