Change isReachable() to return NetworkStatus constant to reachableCallback(reachability) as specified in the API documentation.

This commit is contained in:
Bryce Curtis
2010-09-20 22:25:57 -05:00
parent 1a9173d2c3
commit 063e189bb7
2 changed files with 51 additions and 44 deletions
+6 -33
View File
@@ -4,8 +4,8 @@
* @constructor
*/
function NetworkStatus() {
this.code = null;
this.message = "";
//this.code = null;
//this.message = "";
};
NetworkStatus.NOT_REACHABLE = 0;
@@ -42,38 +42,11 @@ Network.prototype.updateReachability = function(reachability) {
* @param {Object} options (isIpAddress:boolean)
*/
Network.prototype.isReachable = function(uri, callback, options) {
// callback required
if (typeof callback != "function") {
console.log("Network Error: callback is not a function");
return;
var isIpAddress = false;
if (options && options.isIpAddress) {
isIpAddress = options.isIpAddress;
}
PhoneGap.execAsync(
function(status) {
// If reachable, the check for wifi vs carrier
if (status) {
PhoneGap.execAsync(
function(wifi) {
var s = new NetworkStatus();
if (wifi) {
s.code = NetworkStatus.REACHABLE_VIA_WIFI_NETWORK;
}
else {
s.code = NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK;
}
callback(s);
}, null, "Network Status", "isWifiActive", []);
}
// If not
else {
var s = new NetworkStatus();
s.code = NetworkStatus.NOT_REACHABLE;
callback(s);
}
}, null, "Network Status", "isReachable", [uri]);
PhoneGap.execAsync(callback, null, "Network Status", "isReachable", [uri, isIpAddress]);
};
PhoneGap.addConstructor(function() {