This is an old revision of the document!


Check the Network Connection in PhoneGap

Here's a little bit of Javascript code that will check the network connection in PhoneGap to make sure that the internet is available for public requests. In order to be in the app store your app must work in both online and offline modes. This simple code will satisfy those requirements.

// check to see if the network is reachable
setTimeout(function() {
  navigator.network.isReachable("www.google.com",
  networkConnectionCheck, {isIpAddress:false});
}, 500);

function networkConnectionCheck(reachability) {
  if ( reachability.remoteHostStatus == NetworkStatus.NOT_REACHABLE ) {
    navigator.notification.alert("You appear to be offline.", "your app name");
  }
};

comments powered by Disqus
check_the_network_connection_in_phonegap.1366896411.txt.gz · Last modified: 2020/06/01 22:53 (external edit)