Help get this topic noticed by sharing it on Twitter, Facebook, or email.

how to check internet connection

Hi

How to check internet connection, if the device is on or offline and show a message if offline.

Thanks
1 person has
this question
+1
Reply
  • Hello,

    Please use the events online and offline for that or check it with cordova plugin https://cordova.apache.org/docs/en/la...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned happy, confident, thankful, excited kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Antonio you can also call the AppClientGetState function if you are using any API Express calls in your app.

    Below is a snippet from one of my ionic apps where I obtain the state when the app initially loads and then set a listener to track any changes in the state. I write the state to global scope variables so they can easily be displayed back to the user. Hope this helps.
    Thanks

    //
    // Call GetState function to show if app is online/offline
    var requestData = {};
    Apperyio.get("AppClientGetState")(requestData).then(
    function(success){ // success callback
    $scope.appStatus = success.state;
    //
    // Commit changes to global scope
    $scope.$apply();
    },
    function(error){ // callback to handle request error
    },
    function(notify){ // notify callback, can fire few times
    });
    //
    // Create listener for changes in app status
    Apperyio.get("mssdk")().then(function(AppClientInstance){
    //
    // Subscribe to AppClient state updates
    AppClientInstance.on("statechange", function(currentState){
    //
    // Set appStatus & appState scope variables based on app status
    $scope.appStatus = currentState;
    if(currentState === 'offline'){
    $scope.appState = false;
    }
    else if(currentState === 'online'){
    $scope.appState = true;
    }
    else if(currentState === 'sync_failed'){
    Apperyio.get("AppClientGeneralOperations").resetFailedSync();
    }
    //
    // Commit changes to global scope
    $scope.$apply();
    console.log("State changed to " + currentState);
    });
    });
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited sad, anxious, confused, frustrated