Check for internet connection on the device

I’m checking whether there are any petition AJAX or HTTP within my app, and it works perfect, now I want to do the same but verifying whether or not internet connection on the phone to before displaying, display a gif loader on the splashscreen ? is this possible?

Greetings!

Yes!

Use ng-cordova!

http://ngcordova.com/docs/#Network

1 Like

If you choose not to use ngCordova you could also check for an internet connection like below:

ngCordova is the best route now though.

1 Like

thanks for the info now I doubt remains. As I can assess Internet connection before the splash screen? I still unclear after.

1 Like

In android I works really well, but in iOS at all, in fact just checked that my control does not work on ajax.

.config(function ($httpProvider) {
    $httpProvider.responseInterceptors.push('myHttpInterceptor');
    var spinnerFunction = function (data, headersGetter) {
        // todo start the spinner here
        //alert('start spinner');
        $('#mydiv').show();
        return data;
    };
    $httpProvider.defaults.transformRequest.push(spinnerFunction);
})
 // register the interceptor as a service, intercepts ALL angular ajax http calls
.factory('myHttpInterceptor', function ($q, $window) {
    return function (promise) {
        return promise.then(function (response) {
            // do something on success
            // todo hide the spinner
            //alert('stop spinner');
            $('#mydiv').hide();
            return response;

        }, function (response) {
            // do something on error
            // todo hide the spinner
            //alert('stop spinner');
            $('#mydiv').hide();
            return $q.reject(response);
        });
    };
});

You have two ways to check internet

by connection object - install org.apache.cordova.network-information
ngCordova plugin - install ngCordova for your project.

check this url can be useful.

http://goo.gl/eq2SHi