Testing No Connection in apps and strange behavior on iOS

I am working on my No Connection functionality (my app must be connected to work).

I detect the Network Connection and redirect to a page with a retry button and nice message. This works great on Android but not on iOS8 (have not been able to try with iOS7).

In the code below, on Android if I turn off my Wifi and open the App it will show the alerts down the route “2”

On iOS it will show “1”, “1.1” and then nothing. It does not redirect as per $urlRouterProvider.otherwise(’/connectionError’);

To make this example even simpler, just put $urlRouterProvider.otherwise(’/connectionError’); under your stateProvider (with none of the other code below) and turn off your connection and open your app on iOS. It will just show a blank screen. It is definitely not erroring as I tried wrapping it in a Try/Catch.

.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider
     ....  (left out)
    
    //first screen - check if they need to see the tutorial
    try {
        //check that they have a connection first
        if (typeof navigator.connection === 'undefined') {
            alert("1");
            $urlRouterProvider.otherwise('/connectionError');       
             alert("1.1");
        } else if (navigator.connection) {
            
            alert(navigator.connection);
            alert(navigator.connection.type);
            
            if (typeof Connection === 'undefined' || navigator.connection.type === Connection.NONE) {
                alert("2");
                $urlRouterProvider.otherwise('/connectionError');
            } else {
                alert("3");
                checkTutorialFlag();
            }
        } else {
            alert("4");
            checkTutorialFlag();
        }
    } catch (error) {
        //go to the maps
        alert(error);
        
        $urlRouterProvider.otherwise('/app/tabs/gamesMap');
    }
    
    function checkTutorialFlag() {
        //check if they must watch the Tutorial or not
        if (window.localStorage['didTutorial'] === 'true') {
            $urlRouterProvider.otherwise('/app/tabs/gamesMap');
        } else {
            $urlRouterProvider.otherwise('/tutorial');            
        }
    }

Note: The Cordova plug in is installed correctly as iOS offline events and Connection info works fine when I have a connection and turn it off whilst using the app. It is just when you start the app with no connection that it does not work.

So does anyone check the connection when the apps loads?

Hi rodneyjoyce,

Have you been able to figure out this issue in the end? I am facing the same problem.

Cheers,

Alex

Unfortunately not… it is on mu list still to figure out