navigator.onLine is not working in my mobile.How to check internet is online.offline??? In Phonegap

后端 未结 1 1643
盖世英雄少女心
盖世英雄少女心 2021-01-13 03:23

I am using phonegap for my app. My app is basicaly for RSS_FEED from one website. but my requirement is when internet is not there application should alert-

相关标签:
1条回答
  • 2021-01-13 04:16

    please follow the phonegap documentation.

    You could also change the given function to return true or false:

    function checkConnection() {
        var networkState = navigator.connection.type;
    
        var states = {};
        states[Connection.UNKNOWN]  = false;
        states[Connection.ETHERNET] = true;
        states[Connection.WIFI]     = true;
        states[Connection.CELL_2G]  = true;
        states[Connection.CELL_3G]  = true;
        states[Connection.CELL_4G]  = true;
        states[Connection.CELL]     = true;
        states[Connection.NONE]     = false;
        if (states[networkState]) {
            return true;
        } else {
            return false;
        }
    }
    
    0 讨论(0)
提交回复
热议问题