Reputation: 1614
I am using the phonegap1.8.0 and I want to detect if the net is available and then if I could reach it. At the phonegap doc expose the following api
navigator.network.isReachable('www.facebook.com', reachCallBack, {});
however, I got the
Console(4820): Uncaught TypeError: Object #<Object> has no method 'isReachable' at file:///android_asset/www/index.html:71
The code is:
function netIsAvailable()
{
var reachCallBack = function (reachability)
{
var networkState = reachability.code || reachability;
var states = {};
states[NetworkStatus.NOT_REACHABLE] = 'No network connection';
states[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
states[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
alert('Connection type: ' + states[networkState]);
};
alert( navigator.onLine );
navigator.network.isReachable('www.facebook.com', reachCallBack, {});
}
Upvotes: 2
Views: 3437
Reputation: 7659
The isReachable
function is deprecated since v1, and now you have to use connection
or network events to perform the similar logic.
For more detail refer to this group post
Upvotes: 5