Phonegap (online build) app - no internet connection and network status

前端 未结 2 585
庸人自扰
庸人自扰 2020-12-17 23:03

My first jquery mobile app contains elements which needs datas from Internet sources like public Google calendars and Amazon affiliate widgets but it works only when I testi

相关标签:
2条回答
  • 2020-12-17 23:18

    For checking internet connection I use this function:

    function checkConnection(){
                var networkState = navigator.connection.type;
                if(Connection.NONE==networkState)
                    return "<p>No connection</p>";
    }
    

    For being able yo use it you have to add the network state plugin this way:

    cordova plugin add cordova-plugin-network-information
    

    Your AndoidManifest file should include this two lines:

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    
    0 讨论(0)
  • 2020-12-17 23:26

    Add the whitelist plugin

    <gap:plugin name="cordova-plugin-whitelist" source="npm" />
    

    You might need to add this meta tag on the head

    <meta http-equiv="Content-Security-Policy" content="default-src *; style-src *  'unsafe-inline'; script-src *  'unsafe-inline'; media-src *">
    

    And add this two lines to the config.xml

    <allow-navigation href="http://*/*" />
    <allow-intent href="https://*/*" />
    
    0 讨论(0)
提交回复
热议问题