Как использовать плагин сетевого подключения в Cordova

Я разрабатываю приложение для Android с Apache Cordova. После заставки я хочу отобразить сообщение, если интернет-соединение не найдено. Я установил плагин cordova-plugin-network-information, но не знаю, как его использовать. Я читал документацию, но ничего не понял.

Это мой файл index.html:

<!DOCTYPE html>

<html>
    <head>
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Findajob</title>
         <style>
        body, html {
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

        iframe {
            width: 100%;
            height: 100%;
            border: none;
        }
    </style>
    </head>
    <body>
        <iframe height="100%" src="http://www.mywebsite.com/"></iframe>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

Это мой файл index.js:

var app = {

    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    onDeviceReady: function() {
        this.receivedEvent('deviceready');
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

app.initialize();

Это мой файл config.xml:

<?xml version='1.0' encoding='utf-8'?>
<widget id="io.cordova.com" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
    <name>FindaJob</name>
    <description>
        Find jobs in UK.
    </description>
    <author email="[email protected]" href="http://www.findajob.af/">
        Fareed Shuja
    </author>
    <preference name="SplashScreen" value="screen" />
    <preference name="SplashScreenDelay" value="3000" />
    <preference name="SplashMaintainAspectRatio" value="true" />
    <content src="index.html" />
    <access origin="*" />
    <allow-intent href="http://*/*" />
    <allow-intent href="https://*/*" />
    <allow-intent href="tel:*" />
    <allow-intent href="sms:*" />
    <allow-intent href="mailto:*" />
    <allow-intent href="geo:*" />
    <platform name="android">
        <allow-intent href="market:*" />
    </platform>
    <platform name="android">
        <splash density="land-hdpi" src="res/screen/android/screen1l.png" />
        <splash density="land-ldpi" src="res/screen/android/screen2l.png" />
        <splash density="land-mdpi" src="res/screen/android/screen3l.png" />
        <splash density="land-xhdpi" src="res/screen/android/mainscreen.png" />
        <splash density="port-hdpi" src="res/screen/android/screen1p.png" />
        <splash density="port-ldpi" src="res/screen/android/screen2p.png" />
        <splash density="port-mdpi" src="res/screen/android/screen3p.png" />
        <splash density="port-xhdpi" src="res/screen/android/mainscreen.png" />
    </platform>
    <platform name="android">
        <icon density="ldpi" src="res/icon/android/icon-36-ldpi.png" />
        <icon density="mdpi" src="res/icon/android/icon-48-mdpi.png" />
        <icon density="hdpi" src="res/icon/android/icon-72-hdpi.png" />
        <icon density="xhdpi" src="res/icon/android/icon-96-xhdpi.png" />
        <icon density="xxhdpi" src="res/icon/android/icon-144-xxhdpi.png" />
        <icon density="xxxhdpi" src="res/icon/android/icon-192-xxxhdpi.png" />
    </platform>
    <platform name="ios">
        <allow-intent href="itms:*" />
        <allow-intent href="itms-apps:*" />
    </platform>
    <engine name="android" spec="^6.2.3" />
    <engine name="browser" spec="^4.1.0" />
    <plugin name="cordova-plugin-network-information" spec="^1.3.3" />
    <plugin name="cordova-plugin-splashscreen" spec="^4.0.3" />
    <plugin name="cordova-plugin-whitelist" spec="^1.3.2" />
</widget>

Please Help. I simply want to show a

Интернет-соединение не найдено

message if it is not connected to internet.


person Sameer Ali    schedule 07.08.2017    source источник


Ответы (1)


Вы этот плагин

https://github.com/apache/cordova-plugin-network-information

Это предоставит информацию о сотовом и Wi-Fi-соединении устройства.

person PraveenKumar    schedule 08.08.2017