Coder Social home page Coder Social logo

apache / cordova-plugin-network-information Goto Github PK

View Code? Open in Web Editor NEW
462.0 50.0 321.0 435 KB

Apache Cordova Network Information Plugin

Home Page: https://cordova.apache.org/

License: Apache License 2.0

Java 25.88% JavaScript 27.35% Objective-C 46.77%
cordova library objective-c java nodejs javascript mobile android hacktoberfest ios

cordova-plugin-network-information's Introduction

title description
Network Information
Get information about wireless connectivity.

cordova-plugin-network-information

Android Testsuite Chrome Testsuite iOS Testsuite Lint Test

This plugin provides an implementation of an old version of the Network Information API. It provides information about the device's cellular and wifi connection, and whether the device has an internet connection.

To get a few ideas how to use the plugin, check out the sample at the bottom of this page or go straight to the reference content.

Installation

cordova plugin add cordova-plugin-network-information

Supported Platforms

  • Android
  • Browser
  • iOS
  • Windows

Connection

The connection object, exposed via navigator.connection, provides information about the device's cellular and wifi connection.

Properties

  • connection.type

Constants

  • Connection.UNKNOWN
  • Connection.ETHERNET
  • Connection.WIFI
  • Connection.CELL_2G
  • Connection.CELL_3G
  • Connection.CELL_4G
  • Connection.CELL
  • Connection.NONE

connection.type

This property offers a fast way to determine the device's network connection state, and type of connection.

Quick Example

function checkConnection() {
    var networkState = navigator.connection.type;

    var states = {};
    states[Connection.UNKNOWN]  = 'Unknown connection';
    states[Connection.ETHERNET] = 'Ethernet connection';
    states[Connection.WIFI]     = 'WiFi connection';
    states[Connection.CELL_2G]  = 'Cell 2G connection';
    states[Connection.CELL_3G]  = 'Cell 3G connection';
    states[Connection.CELL_4G]  = 'Cell 4G connection';
    states[Connection.CELL]     = 'Cell generic connection';
    states[Connection.NONE]     = 'No network connection';

    alert('Connection type: ' + states[networkState]);
}

checkConnection();

iOS Quirks

  • <iOS7 can't detect the type of cellular network connection.
    • navigator.connection.type is set to Connection.CELL for all cellular data.

Windows Quirks

  • When running in the Phone 8.1 emulator, always detects navigator.connection.type as Connection.ETHERNET.

Browser Quirks

  • Browser can't detect the type of network connection. navigator.connection.type is always set to Connection.UNKNOWN when online.

Network-related Events

offline

The event fires when an application goes offline, and the device is not connected to the Internet.

document.addEventListener("offline", yourCallbackFunction, false);

Details

The offline event fires when a previously connected device loses a network connection so that an application can no longer access the Internet. It relies on the same information as the Connection API, and fires when the value of connection.type becomes NONE.

Applications typically should use document.addEventListener to attach an event listener once the deviceready event fires.

Quick Example

document.addEventListener("offline", onOffline, false);

function onOffline() {
    // Handle the offline event
}

Quirks

This plugin is unable to broadcast events while in the background. Use navigator.connection.type to check connection status on the resume event instead.

iOS Quirks

During initial startup, the first offline event (if applicable) takes at least a second to fire.

online

This event fires when an application goes online, and the device becomes connected to the Internet.

document.addEventListener("online", yourCallbackFunction, false);

Details

The online event fires when a previously unconnected device receives a network connection to allow an application access to the Internet. It relies on the same information as the Connection API, and fires when the connection.type changes from NONE to any other value.

Applications typically should use document.addEventListener to attach an event listener once the deviceready event fires.

Quick Example

document.addEventListener("online", onOnline, false);

function onOnline() {
    // Handle the online event
}

Quirks

This plugin is unable to broadcast events while in the background. Use navigator.connection.type to check connection status on the resume event instead.

iOS Quirks

During initial startup, the first online event (if applicable) takes at least a second to fire, prior to which connection.type is UNKNOWN.

Sample: Upload a File Depending on your Network State

The code examples in this section show examples of changing app behavior using the online and offline events and your network connection status.

To start with, create a new FileEntry object (data.txt) to use for sample data. Call this function from the deviceready handler.

Note This code example requires the File plugin.

var dataFileEntry;

function createSomeData() {

    window.requestFileSystem(window.TEMPORARY, 5 * 1024 * 1024, function (fs) {

        console.log('file system open: ' + fs.name);
        // Creates a new file or returns an existing file.
        fs.root.getFile("data.txt", { create: true, exclusive: false }, function (fileEntry) {

          dataFileEntry = fileEntry;

        }, onErrorCreateFile);

    }, onErrorLoadFs);
}

Next, add listeners for the online and offline events in the deviceready handler.

document.addEventListener("offline", onOffline, false);
document.addEventListener("online", onOnline, false);

The app's onOnline function handles the online event. In the event handler, check the current network state. In this app, treat any connection type as good except Connection.NONE. If you have a connection, you try to upload a file.

function onOnline() {
    // Handle the online event
    var networkState = navigator.connection.type;

    if (networkState !== Connection.NONE) {
        if (dataFileEntry) {
            tryToUploadFile();
        }
    }
    display('Connection type: ' + networkState);
}

When the online event fires in the preceding code, call the app's tryToUploadFile function.

If the upload fails, then call the app's offlineWrite function to save the current data somewhere.

Note For simplicity, file reading & writing was omitted. Refer to the cordova-plugin-file documentation for more information on file handling.

function tryToUploadFile() {
    // !! Assumes variable fileURL contains a valid URL to a text file on the device,
    var fileURL = getDataFileEntry().toURL();
    
    getFileBlobSomehow(fileURL, function(fileBlob) {
        var success = function (r) {
            console.log("Response = " + r.response);
            display("Uploaded. Response: " + r.response);
        };

        var fail = function (error) {
            console.log("An error has occurred: Code = " + error.code || error.status);
            offlineWrite("Failed to upload: some offline data");
        }

        var xhr = new XMLHttpRequest();

        xhr.onerror = fail;
        xhr.ontimeout = fail;
        xhr.onload = function() {
            // If the response code was successful...
            if (xhr.status >= 200 && xhr.status < 400) {
                success(xhr);
            }
            else {
                fail(xhr)
            }
        }

        // Make sure you add the domain of your server URL to the
        // Content-Security-Policy <meta> element in index.html.
        xhr.open("POST", encodeURI(SERVER));

        xhr.setRequestHeader("Content-Type", "text/plain");

        // The server request handler could read this header to
        // set the filename.
        xhr.setRequestHeader("X-Filename", fileURL.substr(fileURL.lastIndexOf("/") + 1));

        xhr.send(fileBlob);
    });
};

Here is the code for the offlineWrite function.

Note This code examples requires the File plugin.

function offlineWrite(offlineData) {
    // Create a FileWriter object for our FileEntry.
    dataFileEntry.createWriter(function (fileWriter) {

        fileWriter.onwriteend = function () {
            console.log("Successful file write...");
            display(offlineData);
        };

        fileWriter.onerror = function (e) {
            console.log("Failed file write: " + e.toString());
        };

        fileWriter.write(offlineData);
    });
}

If the offline event occurs, just do something like notify the user (for this example, just log it).

function onOffline() {
    // Handle the offline event
    console.log("lost connection");
}

cordova-plugin-network-information's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

cordova-plugin-network-information's Issues

Type none when change type Network un app background

Hello, I have a problem with Internet connections, I use the ionic Network plugin and the problem I have is, when the connection type changes from wifi to data and the application is in the background the type of connection it receives is NONE, I have to kill the application and start it again so that everything goes correctly, has anyone experienced this problem?

Determine if a specific connection type is available

Feature Request

Determine if a specific connection type is available

Motivation Behind Feature

I have a dial feature visible only when cellular connections are present. If the user has both cellular and wifi access, the plugin returns wifi as the connection type but never tells one that cellular is also available.

Feature Description

bool = Connection.hasConnection(Connection.CELL_4G);

Alternatives or Workarounds

I got nothing... no idea how to pursue this. I can't very well popup an alert and tell people to turn off their wifi to access the dial feature.

network.connection.type is always unkown on iOS 13.2.2

Bug Report

Problem

network.connection.type is always unkown though I had connected to wifi and mobile data connection.

What is expected to happen?

network.connection.type = "WIFI"

What does actually happen?

network.connection.type = "unkonwn"

Information

I followed this documentation: https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-network-information/index.html

Environment, Platform, Device

iPhone XR running on iOS 13.2.2

Version information

Cordova version: 9.0.0 ([email protected])
node version: v12.8.1
npm version: 6.13.0

ordova-plugin-add-swift-support 2.0.2 "AddSwiftSupport"
cordova-plugin-barcodescanner 0.7.4 "BarcodeScanner"
cordova-plugin-battery-status 2.0.3 "Battery"
cordova-plugin-camera 4.1.0 "Camera"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-media-capture 3.0.3 "Capture"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-splashscreen 5.0.3 "Splashscreen"
cordova-plugin-vibration 3.1.1 "Vibration"
cordova-plugin-whitelist 1.3.3 "Whitelist"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

core.js:6014 ERROR RangeError: Maximum call stack size exceeded

image

ionic 4,5 triggering this issue.

"dependencies": {
"@angular/animations": "~8.2.14",
"@angular/cdk": "~8.2.3",
"@angular/common": "~8.2.14",
"@angular/core": "~8.2.14",
"@angular/forms": "~8.2.14",
"@angular/http": "^7.2.16",
"@angular/material": "^8.2.3",
"@angular/material-moment-adapter": "^9.0.1",
"@angular/platform-browser": "~8.2.14",
"@angular/platform-browser-dynamic": "~8.2.14",
"@angular/router": "~8.2.14",
"@ionic-native/app-version": "^5.22.0",
"@ionic-native/camera": "^5.21.5",
"@ionic-native/core": "^5.0.0",
"@ionic-native/file": "^5.21.5",
"@ionic-native/file-transfer": "^5.21.6",
"@ionic-native/image-picker": "^5.21.5",
"@ionic-native/keyboard": "^5.21.5",
"@ionic-native/network": "^5.23.0",
"@ionic-native/splash-screen": "^5.0.0",
"@ionic-native/status-bar": "^5.0.0",
"@ionic/angular": "^5.0.0",
"@ionic/storage": "^2.2.0",
"@types/hammerjs": "^2.0.36",
"cordova-android": "^7.1.4",
"cordova-plugin-app-version": "^0.1.9",
"cordova-plugin-camera": "^4.1.0",
"cordova-plugin-device": "^2.0.3",
"cordova-plugin-file": "^6.0.2",
"cordova-plugin-file-transfer": "^1.7.1",
"cordova-plugin-ionic-keyboard": "^2.2.0",
"cordova-plugin-ionic-webview": "^4.1.3",
"cordova-plugin-network-information": "^2.0.2",
"cordova-plugin-splashscreen": "^5.0.3",
"cordova-plugin-statusbar": "^2.4.3",
"cordova-plugin-telerik-imagepicker": "^2.3.3",
"cordova-plugin-whitelist": "^1.3.4",
"cordova-sqlite-storage": "^4.0.0",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"moment": "^2.24.0",
"ngx-material-timepicker": "^5.1.0",
"rxjs": "~6.5.1",
"tslib": "^1.9.0",
"zone.js": "~0.9.1"
},

Issue with Ionic-native/network onConnect() on upgrade to Angular 10

I have an issue with onConnect() in ionic-native/network on uprade to angular 10. It is stating that Object(...) is not a function while accessing any function from Network. Could not get why it is happening?

Version which I am using
cordova-plugin-network-information -- 2.0.2
ionic-native/network - 3.7.0

net::ERR_INTERNET_DISCONNECTED with cordova-plugin-network-information

Bug Report

Problem

net::ERR_INTERNET_DISCONNECTED error occurs when cordova-plugin-network-information plugin is added and no internet connectivity is available.

What is expected to happen?

cordova-plugin-network-information should provide ability to check whether internet connectivity is available but not terminate the application from the lack of internet. What I plan to do by design is check within VueJS context for network connectivity and show a VueJS offline page but I can't do this is cordova-plugin-network-information prevents me from getting to VueJS context.

What does actually happen?

net::ERR_INTERNET_DISCONNECTED error occurs when cordova-plugin-network-information plugin is added and application is halted from proceeding to VueJS pages.

Information

The following steps can be taken to reproduce the issue.

  1. vue create offline (use default settings)
  2. cd offline
  3. vue add cordova (press enter on everything and only select android platform)
  4. cd src-cordova
  5. cordova plugin add cordova-plugin-network-information
  6. add the following to VueJS index.html at bottom.

<script type="text/javascript" src="index.js"></script>

  1. create index.js with the following.
var app = {
  initialize: function () {
    document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
  },
  onDeviceReady: function () {
    document.addEventListener("offline", function (e) {
      alert ("offline detected!");
    }, false);
    this.receivedEvent('deviceready');
  }
};
app.initialize();
  1. setup Android Studio for Pixel-2-API-R emulation
  2. npm run cordova-serve-android
  3. After android emulator has application installed, go to top navigation menu and turn off cell via the bi-directional icon.
  4. Navigate and run VueExampleAppName which was just installed
  5. Upon startup, you should get something similar to the following where LOCALHOST is the machine's local IP address.
Webpage not available

The webpage at http://LOCALHOST:8080/ could not be loaded becasue:

net::ERR_INTERNET_DISCONNECTED

While it is true that there is no internet, the problem is that the plugin is supposed to only provide network information. The application should still allow to run and show the VueJS page. Removing the plugin, does resolve the issue but network detecting for user notification is still desired for complete product implementation.

The desired result would be to show the VueJS page regardless of whether internet is available. The plugin does work fine if WiFi is not available but not when there is no internet/cell network.

Command or Code

See above.

Environment, Platform, Device

Development is done on Windows 10 Enterprise. Not sure if it matters, but I have Android Studio version 3.6.1 which was used to setup Pixel-2-API-R android emulator.

Version information

Only android platform is use as shown in the example above.

Dependencies in package.json are as follows.

"cordova-android": "~8.1.0",
"cordova-plugin-network-information": "^2.0.2"

VueJS package.json does have vue-cli-plugin-cordova which might be relevant. The devDependencies for VueJS package.json is as follows.

"@vue/cli-plugin-babel": "~4.3.0",
"@vue/cli-plugin-eslint": "~4.3.0",
"@vue/cli-service": "~4.3.0",
"babel-eslint": "^10.1.0",
"eslint": "^6.7.2",
"eslint-plugin-vue": "^6.2.2",
"vue-cli-plugin-cordova": "~2.4.1",
"vue-template-compiler": "^2.6.11"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

What exactly is triggering online/offline events?

What specifically is triggering the offline event?

What if a user is connected to wifi that has no internet? Or happens to be transitioning from Cell to Wifi....or transition between wifis. OR....the user connects to a wifi, but they must authenticate (guest internet) via a web url. In all these scenarios, the The wifi port is up...user is getting an IP address but can't get to the internet? What is being evaluated in a situation like this to determine if the user is actually online?

I have a very specific case where this has happened to a user and when launched my app went white screen. We could replicate this several times on iOS (like 1 out of every 10 times), but seemingly have never had a problem on Android (that I know of). The iOS user is def a rare case but I need to understand why this is happening so I can compensate for these scenario so my app doesn't hang on launch.

If the user loses internet while the app is launched then everything works fine.

Its only on app launch for iOS. I have document.addEventListener("online", function() {}) ; at the top of my deviceReady section and it should fire during this odd situation...but its not....and the app is hanging.

Version 2.0.2 from npmjs is crashing some devices with Android 10, on startup.

Bug Report

Problem

Version 2.0.2 from npmjs is crashing some devices with Android 10, on startup.

What is expected to happen?

Run on Android Studio. You can also reproduce from the AVD Emulator (Android 10, Pixel3A).

What does actually happen?

Crashes on startup.

Information

Uncaught exception from plugin:
Connectivity Service : Neither user 10381 nor current process has android.permission.ACCESS_NETWORK_STATE

image

Possible similar case: https://stackoverflow.com/questions/24552015/java-lang-securityexception-connectivityservice-neither-user-10134-nor-current

Environment, Platform, Device

Android 10, Pixel 3A.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Android no internet triggering `online` function

Bug Report

Problem:

On Android, app starts with internet access, move phone into airplane mode and the online function triggers when the offline function should trigger. This is happening about 50% of the time. After taking phone off airplane mode, I can see online function trigger again and then on a 2nd time putting phone into airplane mode do I finally see it go offline

What is expected to happen?

Moving phone into airplane mode should trigger the offline function - every time.

What does actually happen?

On first time putting phone into airplane mode - I see online function trigger. After restoring phone and then putting back into airplane mode a 2nd time, the offline triggers as its supposed to. Its only happening on the first time.

Information

Included above.

Command or Code

Plugin version 2.0.2

Environment, Platform, Device

Android...its happening on Android 5 through 9. - all my test devices.

Version information

Plugin Version: 2.0.2

Ionic:
Ionic CLI : 5.4.2 (C:\Users\RPO\AppData\Roaming\npm\node_modules\ionic)
Ionic Framework : ionic1 1.0.0
@ionic/v1-toolkit : 1.0.22

Cordova:
Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, (and 30 other plugins)

Utility:
cordova-res : 0.6.0
native-run : 0.2.8

System:
NodeJS : v10.16.3 (C:\Program Files\nodejs\node.exe)
npm : 6.4.0
OS : Windows 7

Checklist

  • [x ] I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • [x ] I included all the necessary information above

Online event fires every time app resumes from background (iOS and Android)

Bug Report

Problem

The online event fires unreliably when an app moves from background to foreground.
This occurs on iOS AND Android for us.
It might be related to #82 but it is definitely not resolved with 2.0.2

What is expected to happen?

Online event only fires when network connection was lost and is established again.

What does actually happen?

Online event fires every time the app was in background and comes to foreground again, even though wifi is connected at all times.

Information

We show a message to the user when he goes offline, and one when he goes online again, so we rely on the event listeners.

Offline works fine, but the online event fires every time the App comes from background to foreground although wifi is connected at all times.

The connection seems to go to `type: none' when the App goes to background, which makes the online event fire when the app comes to foreground again.

We pretty much use the code as in the Cordova documentation, so there's no special implementation that could affect the behavior.

Environment, Platform, Device

Tested on iOS (12.4) and Android (9 and 6.0.1)

Version information

React
cordova 9.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Error installing plugin

{
"name": "IonicFirebaseAuth",
"version": "0.0.1",
"author": "Ionic Framework",
"homepage": "http://ionicframework.com/",
"private": true,
"scripts": {
"clean": "ionic-app-scripts clean",
"build": "ionic-app-scripts build",
"lint": "ionic-app-scripts lint",
"ionic:build": "ionic-app-scripts build",
"ionic:serve": "ionic-app-scripts serve",
"compodoc": "./node_modules/.bin/compodoc -d ./docs/ -p ./tsconfig.json"
},
"dependencies": {
"@angular/common": "4.1.0",
"@angular/compiler": "4.1.0",
"@angular/compiler-cli": "4.1.0",
"@angular/core": "4.1.0",
"@angular/forms": "4.1.0",
"@angular/http": "4.1.0",
"@angular/platform-browser": "4.1.0",
"@angular/platform-browser-dynamic": "4.1.0",
"@compodoc/compodoc": "^1.0.7",
"@ionic-native/background-geolocation": "^4.5.3",
"@ionic-native/core": "3.7.0",
"@ionic-native/device": "^4.5.3",
"@ionic-native/diagnostic": "^4.5.3",
"@ionic-native/firebase": "^4.12.2",
"@ionic-native/geolocation": "^4.5.3",
"@ionic-native/google-maps": "^4.5.3",
"@ionic-native/splash-screen": "3.7.0",
"@ionic-native/status-bar": "3.7.0",
"@ionic/storage": "2.0.1",
"angularfire2": "^5.0.0-rc.3",
"cordova-android": "7.1.0",
"cordova-android-firebase-gradle-release": "^1.0.3",
"cordova-android-play-services-gradle-release": "^1.4.4",
"cordova-browser": "5.0.3",
"cordova-plugin-device": "^1.1.7",
"cordova-plugin-firebase": "^2.0.1",
"cordova-plugin-geolocation": "^4.0.1",
"cordova-plugin-ionic-webview": "^1.2.1",
"cordova-plugin-splashscreen": "^4.1.0",
"cordova-plugin-whitelist": "^1.3.3",
"cordova-support-google-services": "^1.1.0",
"cordova.plugins.diagnostic": "^3.9.2",
"firebase": "^4.9.0",
"geofire": "^4.1.2",
"gulp-sass": "4.0.1",
"heatmap.js": "^2.0.5",
"ionic-angular": "3.2.1",
"ionic-native": "^2.9.0",
"ionic-plugin-keyboard": "^2.2.1",
"ionicons": "3.0.0",
"ng2-translate": "^5.0.0",
"phonegap-plugin-multidex": "^1.0.0",
"phonegap-plugin-push": "^2.2.3",
"rxjs": "^5.5.12",
"sw-toolbox": "3.6.0",
"zone.js": "0.8.10"
},
"devDependencies": {
"@ionic/app-scripts": "1.3.7",
"typescript": "2.2.1"
},
"description": "An Ionic project",
"cordova": {
"plugins": {
"ionic-plugin-keyboard": {},
"cordova-plugin-whitelist": {},
"cordova-plugin-device": {},
"cordova-plugin-splashscreen": {},
"cordova-plugin-ionic-webview": {},
"cordova-plugin-geolocation": {},
"cordova-plugin-firebase": {},
"cordova-android-play-services-gradle-release": {
"PLAY_SERVICES_VERSION": "15.+"
},
"cordova-android-firebase-gradle-release": {
"FIREBASE_VERSION": "15.+"
}
},
"platforms": [
"browser",
"android"
]
}
}

Error:
cordova plugin add cordova-plugin-network-information
(node:8072) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): CordovaError: Failed to fetch plugin cordova-plugin-network-information via registry.
Probably this is either a connection problem, or plugin spec is incorrect.
Check your connection and plugin name/version/URL.
Error: cmd: Command failed with exit code 1 Error output:
npm ERR! code EINVALIDTYPE
npm ERR! typeerror Error: Argument #5: Expected object but got boolean
npm ERR! typeerror at inflatableChild (C:\Program Files\nodejs\node_modules\npm\lib\install\inflate-shrinkwrap.js:70:3)
npm ERR! typeerror at BB.each (C:\Program Files\nodejs\node_modules\npm\lib\install\inflate-shrinkwrap.js:52:12)
npm ERR! typeerror at tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
npm ERR! typeerror at Object.gotValue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\reduce.js:155:18)
npm ERR! typeerror at Object.gotAccum (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\reduce.js:144:25)
npm ERR! typeerror at Object.tryCatcher (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\util.js:16:23)
npm ERR! typeerror at Promise._settlePromiseFromHandler (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:512:31)
npm ERR! typeerror at Promise._settlePromise (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:569:18)
npm ERR! typeerror at Promise._settlePromise0 (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:614:10)
npm ERR! typeerror at Promise._settlePromises (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\promise.js:693:18)
npm ERR! typeerror at Async._drainQueue (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:133:16)
npm ERR! typeerror at Async._drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:143:10)
npm ERR! typeerror at Immediate.Async.drainQueues (C:\Program Files\nodejs\node_modules\npm\node_modules\bluebird\js\release\async.js:17:14)
npm ERR! typeerror at runCallback (timers.js:789:20)
npm ERR! typeerror at tryOnImmediate (timers.js:751:5)
npm ERR! typeerror at processImmediate [as _immediateCallback] (timers.js:722:5)
npm ERR! typeerror This is an error with npm itself. Please report this error at:
npm ERR! typeerror https://github.com/npm/npm/issues

npm ERR! A complete log of this run can be found in:
npm ERR! C:\Users\Usuario\AppData\Roaming\npm-cache_logs\2019-01-29T22_27_16_384Z-debug.log
(node:8072) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with
a non-zero exit code.

Correct network detection API calls deprecated on Android and iOS

Bug Report

Problem

What is expected to happen?

Native Android and iOS code should use not-deprecated API calls.

What does actually happen?

Some Android and iOS native methods used are deprecated.

Information

Command or Code

Environment, Platform, Device

Android and iOS

Version information

Current master branch, version 3.0.0-dev.

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

bug: 'onConnect' does not work as expected

Bug Report

Problem

I need to run an event when connecting to wifi, but it ends up running at unexpected times.

What is expected to happen?

The expected is to occur only when connecting to the internet.

What does actually happen?

The onConnect subscription is firing when the application is opened, minimized> open, when connected to the internet.

Information

Open the application, minimize and open that the onConnect event will be triggered.

Command or Code

https://github.com/UesleyCarossi/test-network

Environment, Platform, Device

Version information

Ionic:

   Ionic CLI                     : 5.4.1 (C:\Users\****\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 5.1.1
   @angular-devkit/build-angular : 0.901.7
   @angular-devkit/schematics    : 9.1.7
   @angular/cli                  : 9.1.7
   @ionic/angular-toolkit        : 2.2.0

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : android 8.0.0
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 4.2.1, (and 5 other plugins)

Utility:

   cordova-res : 0.6.0
   native-run  : 0.2.8

System:

   Android SDK Tools : 26.1.1 (C:\Android\sdk)
   NodeJS            : v10.16.0 (C:\Program Files\nodejs\node.exe)
   npm               : 6.9.0
   OS                : Windows 10

Plugins:

cordova-plugin-device 2.0.2 "Device" cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard" cordova-plugin-ionic-webview 4.2.1 "cordova-plugin-ionic-webview" cordova-plugin-network-information 2.0.2 "Network Information" cordova-plugin-splashscreen 5.0.2 "Splashscreen" cordova-plugin-statusbar 2.4.2 "StatusBar" cordova-plugin-whitelist 1.3.3 "Whitelist"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

getCurrrentConnectionType for Windows may not be accurate for some locked down corporate networks

Bug Report

Problem

I am not sure if you want to consider this a bug, as perhaps my use case is a bit out of the ordinary, but thought would just bring to light.

For now, I have called the Windows API directly to get around this.

Running on a more "locked down" corporate network, getCurrrentConnectionType() would return NONE for windows when trying to get to a local server (ie server on the same network)

Seems only to be Windows, the problem occurs, Have not tried iOS yet, but Android appear ok.

What is expected to happen?

Would like this to report the connected network

What does actually happen?

getCurrrentConnectionType returns NONE

Information

In my case, the call to profile.getNetworkConnectivityLevel(); was returning NetworkConnectivityLevel.LocalAccess, but if I did a http call anyway, it worked fine

Command or Code

Environment, Platform, Device

A locked down corporate network that probably did not allow outside network access, but in this case the server is located on the local network

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Connection reported as Connection.NONE

I've several reports of iOS users with “Connection.NONE” when they are confirming that they have connection to internet (wifi or another type). I don't know where is the specific trigger of this issue, so I'm not able to reproduce it (yet).

My code is:

var networkState = navigator.connection.type;
if (networkState == Connection.NONE) {
// alert the user using a dialog (navigator.notification.confirm)
}

This code worked perfect in the past.

Environment: Cordova 6.0.0 / Cordova iOS 4.1.1 / Plugin version: 1.3.0

If "Connection.NONE", my app presents a native dialog with the message "No Internet connection found" and after tap the "OK" button, checks again the connection. Users confirming that they have connection to internet. After the second checking, same issue, "Connection.NONE" and the dialog appears again, entering in a loop.

In my own device (Iphone 6 plus), using iOS 11.0, I saw the same issue several times, with the difference that in the second checking, the plugin worked fine.

I asked one user (Iphone 8 plus, iOS 11.4.1), to turn off / on the Iphone and it seems that the problem dissapears, after some time appears again. I asked now to activate/deactivate the flight mode, expecting reply.

IOS 13.4 not working offline

Bug Report

Problem

What is expected to happen?

I am currently conducting tests on iOS 13.4.
I turned off the Lte and turned off the Wi-Fi connection.
However, plug-in run online functions.
The current network status is also displayed as Wi-Fi.

How can i do?

What does actually happen?

The current network status is also displayed as Wi-Fi.

Information

It should be displayed offline when there is no Wi-Fi connection in iOS 13.4.

Command or Code

Environment, Platform, Device

IOS 13.4 (IPhone X)

Version information

Cordova-ios => 5.11
Plugin => 2.0.2

Checklist

  • [ O ] I searched for existing GitHub issues
  • [ O ] I updated all Cordova tooling to most recent version
  • [ O ] I included all the necessary information above

NFC scan fire onConnect event on Android device

Bug Report

NFC scan fire onConnect event

Problem

When I scan an NFC Tag using ionic recommended nfc plugin "chariotsolutions/phonegap-nfc". Then the onConnect event is fired. And it says that "wifi" ist connected:

Connection: {UNKNOWN: "unknown", ETHERNET: "ethernet", WIFI: "wifi", CELL_2G: "2g", CELL_3G: "3g", …

What is expected to happen?

The onConnect event should not be fired when you scan an NFC tag.

What does actually happen?

The onConnect event is fired when you scan an NFC tag.

Information

It happens in an ionic app.

Command or Code

Environment, Platform, Device

Tested on Android 5.01 and 9 devices

Version information

Installed versions:
"@ionic-native/network": "^5.11.0",
"cordova-plugin-network-information": "2.0.2",
@ionic-native/nfc": "^5.3.0",
"phonegap-nfc": "^1.0.3",
"@ionic/angular": "^4.9.1",
"cordova-android": "^7.1.4",

Checklist

  • [x ] I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • [x ] I included all the necessary information above

Online not firing on iOS

Online event isn't firing on iOS.

Environment:
iOS iPhone 5 emulator. iOS version: 10.3.1
Also tried same thing on iOS iPhone 6s emulator with iOS 11.4
On physical iPhone 5 with iOS 11.4.1 everything seems to work. Does the plugin have problems in the emulator?

cordova platforms   iOS 4.5.5

Steps to repeat:
cordova create test
cordova platforms add ios@latest
Add this to index.js:

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

        document.addEventListener("online", () => { 
		console.log("ONLINE")
        }, false);
        document.addEventListener("offline", () => { 
		console.log("OFFLINE")
        }, false);
    },

On the machine running the emulator turn off all network access.

At this point "OFFLINE" prints (good!)

Turn on network access on the computer running the emulator.

Expect to see "ONLINE" but I see nothing.

Problem with the if function

Issue Type

  • Bug Report
  • Feature Request
  • Support Question

The plugin don't work when I try to compare two string with each other.

Information

Command or Code

document.addEventListener("online", onOnline, false);

function onOnline() {
    var event = new Date();
    var day = event.toLocaleDateString();

    var dTag1 = new Date(2019, 5, 2);
    var sTag1 = dTag1.toLocaleDateString();

    if (day == sTag1) {
        document.getElementById("test").innerhtml = "true";
    } 
       
    }

Environment, Platform, Device

Version information

Checklist

  • I searched for already existing GitHub issues about this
  • I updated all Cordova tooling to their most recent version
  • I included all the necessary information above

Object(...) is not a function

Hello,

i am tring to integrate a network check to my ionic app, so I can do work when the device has internet connection. The problem that I have is, that the app (browser and android) crashes with the following error:

logger.ts:67 TypeError: Object(...) is not a function
at Network.onConnect (index.js:62)
at MyApp.webpackJsonp.820.MyApp.manageNetworkConnection (app.component.ts:251)
at app.component.ts:205
at t.invoke (polyfills.js:3)
at Object.onInvoke (core.js:4760)
at t.invoke (polyfills.js:3)
at r.run (polyfills.js:3)
at polyfills.js:3
at t.invokeTask (polyfills.js:3)
at Object.onInvokeTask (core.js:4751)

My code is as follows:

import { Network } from '@ionic-native/network/ngx';

constructor(private network: Network) {

    this.platform.ready().then(() => {
        this.manageNetworkConnection();
    }
}

manageNetworkConnection() {
    //Watch for a connection
    let connectSubscription = this.network.onConnect().subscribe(() => {
        console.log('network connected!');
        setTimeout(() => {
            console.log('we got a connection, woohoo!');
        }, 3000);
    });

    //Watch for disconnecting a network
    let disconnectSubscription = this.network.onDisconnect().subscribe(() => {
        console.log('network was disconnected');
    });
}

I have to use the "ngx"-part for the import, otherwise it tells me, it "Cannot find name 'Network'".
Does somebody know, how I can fix that problem? I couldn't find anything related to this.

Thanks in advance

onDisconnect, onConnect observables never firing

Issue:

Observables not firing,

$ ionic cordova plugin add cordova-plugin-network-information
$ npm install --save @ionic-native/network

package.json

"@ionic-native/network": "^4.12.2",
"cordova-plugin-network-information": "^2.0.1",

app.module.ts

import { Network } from "@ionic-native/network";

@NgModule({
  declarations: [ MyApp ],
  imports: [
    BrowserModule,
    ...
    IonicModule.forRoot(MyApp)
  ],
  bootstrap: [ IonicApp ],
  entryComponents: [ MyApp ],
  providers: [
    ...
    Network
  ]
})

My code


ionViewDidLoad() {
    ...
    this.loadConnectionSubscriptions();
  }

async loadConnectionSubscriptions() {
    console.log(await new Promise(resolve => { setTimeout(() => { resolve(this.network.type); }, 3000); }));
    this.onConnectSubscription = this.network.onConnect().subscribe(
      () => {
        // Wait for connection info to be available
        setTimeout(() => {
          switch (this.network.type) {
            case "2g":
            case "3g":
            case "4g":
            case "cellular":
            case "ethernet":
            case "wifi":
              this.hasConnection = true;
              break;
            case "unknown":
            case "none":
              this.hasConnection = false;
              break;
            default:
              this.hasConnection = true;
              break;
          }
        }, this.WAIT_TIME);
      },
      error => {
        // Unable to fetch connection (?)
        this.alertCtrl
          .create({
            title: "Error fetching connection status",
            subTitle: `${error}`,
            buttons: ["Ok"]
          })
          .present();
      }
    );
    this.onDisconnectSubscription = this.network.onDisconnect().subscribe(
      () => {
        console.log(`${this.network.type}`);
        this.hasConnection = false;
      },
      error => {
        // Unable to fetch connection (?)
        this.alertCtrl
          .create({
            title: "Error fetching connection status",
            subTitle: `${error}`,
            buttons: ["Ok"]
          })
          .present();
      }
    );
  }

Expected behavior:

  • hasConnection variable must be set to true when connection is available
  • The following line: console.log(await new Promise(resolve => { setTimeout(() => { resolve(this.network.type); }, 3000); })); should yield the connection type, but it does yield null on both android and browser.
  • onDisconnect should set hasConnection to false

Current behavior:

  • Both observables (onConnect, onDisconnect) never call their subscribers
    • The following line: console.log(await new Promise(resolve => { setTimeout(() => { resolve(this.network.type); }, 3000); })); should return "unknown" on browser or the current network type

Disclaimer

I do apologize if this is an error related to ionic's implementation of your plugin, but i think it's worth to check.

OnConnect event fired when USB device connected on Android. Using latest version.

Bug Report

OnConnect event fired when USB device connected on Android. It's on Ionic 5 app. I have tested on two real devices.

When downgrading to 2.0.1 everything works fine. Is there another fix?

Version information

Ionic CLI : 5.4.15 (/usr/lib/node_modules/ionic)
Ionic Framework : @ionic/angular 4.11.5
@angular-devkit/build-angular : 0.801.3
@angular-devkit/schematics : 8.1.3
@angular/cli : 8.1.3
@ionic/angular-toolkit : 2.1.1
Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 8.1.0
cordova-plugin-network-information: 2.0.2

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Need 1.2.2-dev version

Need 1.2.2-dev version

I used it in my cordova application.
But now i didn't find this version. When i used older or latest version of this plugin my application is not working. Eagerly need this version.

New option to keep event receiver when a new URL is loaded on webview

Feature Request

New option to keep event receiver when a new URL is loaded on webview

Motivation Behind Feature

If you load a different URL on Cordova Webview, the onPause() and onDestroy() methods of NetworkManager are called in PluginManager.init() and the event receiver is removed . The event listener is not recovered with onResume() as the plugin has not the 'onload' flag set to true (if you force it on config.xml the notifications still do not work).
This behavior is problematic if your application loads several URLs during its life-cycle.

Feature Description

A new option to customize this behavior.

Alternatives or Workarounds

I found no workarounds without changing the plugi's source code.

Non-existent proxy resulting in no internet connection is reported as "wifi"

In android connect device to wifi and then configure a proxy to the wifi connection such that the proxy ip address is random non-existent.
The plugin will report in navigator.connection.type the value "wifi" and will not detect that there is no internet connection. So checking internet connectivity using the plugin is unreliable.

ERROR RangeError: Maximum call stack size exceeded

Hello,

I'm trying to use this plugin in ionic 4 beta.7. It worked fine in ionic 3 but now causes:

ERROR RangeError: Maximum call stack size exceeded
at setupSubscription (fromEvent.js:27)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46)
at setupSubscription (fromEvent.js:46) in core.js

Commenting out the following lines removes the error:

this.network.onDisconnect().subscribe(() => { });

network.type is set to 'wifi' even when iPad Air is set to flight modus or when I am turning off WiFi

Bug Report

network.type is set to 'wifi' even when iPad Air is set to flight modus or when I am turning off WiFi

Problem

network.type is set to 'wifi' even when iPad Air is set to flight modus or when I am turning off WiFi

What is expected to happen?

network.type should be 'none' when iPad Air is set to flight modus or when I am turning off WiFi

What does actually happen?

network.type is still 'wifi' although iPad Air is off network

Information

Command or Code

let online: boolean = window['cordova' as string] ? this.network.type !== 'none' : navigator.onLine !== false;
console.log(this.network.type); // prints 'wifi' even when device is off network
if (online === false) {
   // show a toastMessage device has no internet connection
}

Environment, Platform, Device

iPad Air v12.5.5 PHYSICAL DEVICE (not emulator)

Version information

Ionic:

Ionic CLI : 5.4.16
Ionic Framework : @ionic/angular 5.5.5
@angular-devkit/build-angular : 0.1000.8
@angular-devkit/schematics : 10.0.5
@angular/cli : 10.2.3
@ionic/angular-toolkit : 2.3.3

Capacitor:

Capacitor CLI : not installed
@capacitor/core : not installed

Cordova:

Cordova CLI : 9.0.0 ([email protected])
Cordova Platforms : android 9.1.0, ios 6.2.0
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 17 other plugins)

Utility:

cordova-res (update available: 0.15.3) : 0.14.0
native-run : 1.5.0

System:

Android SDK Tools : 26.1.1 (/Users/a.karavasili/Library/Android/sdk)
ios-deploy : 1.10.0
ios-sim : 8.0.2
NodeJS : v10.19.0 (/Users/a.karavasili/.nvm/versions/node/v10.19.0/bin/node)
npm : 6.13.4
OS : macOS Monterey
Xcode : Xcode 12.4 Build version 12D4e

"@ionic-native/network": "^5.36.0"
"cordova-plugin-network-information": "^3.0.0"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

How to install specific version?

Hallo guys!

if I do cordova plugin add [email protected] then in package.json I see only
image

and package-lock.json doesn't contain any information of plugin version

only if I downgrade plugin to v2.0.2 it will be added to the dependencies list and in package-lock file.

Network type not updating during runtime

Bug Report

Problem

What is expected to happen?

When the network type changes the type-property should update accordingly.

What does actually happen?

When the type-property changes on app start and resumption only.

Information

Plugin Version 2.0.2

Command or Code

setInterval(
      () => console.warn(navigator.connection.type),
      500);

Environment, Platform, Device

Android 8 & 9. (Device & Emulator)

Version information

Ionic:

   Ionic CLI          : 5.4.4 (/usr/local/lib/node_modules/ionic)
   Ionic Framework    : ionic-angular 3.9.9
   @ionic/app-scripts : 3.2.4

Cordova:

   Cordova CLI       : 9.0.0 ([email protected])
   Cordova Platforms : android 8.1.0, ios 5.0.1
   Cordova Plugins   : cordova-plugin-ionic-webview 2.5.2, (and 18 other plugins)

Utility:

   cordova-res : 0.6.0 (update available: 0.8.1)
   native-run  : 0.2.9 

System:

   Android SDK Tools : 26.1.1 (/Users/xxx/Library/Android/sdk)
   ios-deploy        : 1.9.4
   ios-sim           : 8.0.2
   NodeJS            : v12.6.0 (/usr/local/Cellar/node/12.6.0/bin/node)
   npm               : 6.10.2
   OS                : macOS Catalina
   Xcode             : Xcode 11.1 Build version 11A1027

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

iOS App closes, When network connection is off

iOS App closes on Splashscreen, When network connection is off.

If my network connection is off, i want the app shows popup contain.. "There is no connection."
App is not to be closed.

Error initializing Network Connection: Class not found

When upgrading android to 7.1.1 we face an issue of Network Connection: class not found error.
when app is opened comes an alert ' [ERROR] Error initializing Cordova: Class not found'

Chrome dev debug tool :
Error initializing Network Connection: Class not found network.js:88

Online event not firing on iOS or Android

Steps to repeat:

  1. Create a Cordova/Ionic app.
  2. Listen for onConnect events:
document.addEventListener('online', onOnline, false);
function onOnline() {
    // This never fires
    console.log('I\'m online!');
}
Cordova:

   cordova (Cordova CLI) : 8.1.2 ([email protected])
   Cordova Platforms     : android 7.1.2, ios 4.5.5
   Cordova Plugins       : cordova-plugin-ionic-keyboard 2.1.2, cordova-plugin-ionic-webview 2.1.4, (and 14 other plugins)

System:
   Android SDK Tools : 26.1.1 (/Users/username/Library/Android/sdk)
   ios-deploy        : 1.9.4
   ios-sim           : 7.0.0
   NodeJS            : v10.13.0 (/Users/username/.nvm/versions/node/v10.13.0/bin/node)
   npm               : 6.4.1
   OS                : macOS High Sierra
   Xcode             : Xcode 10.1 Build version 10B61

Wrong typing for Connection

Bug Report

Problem

Interface 'Navigator' incorrectly extends interface 'NavigatorNetworkInformation'.
Types of property 'connection' are incompatible.
Property 'dispatchEvent' is missing in type 'Connection' but required in type 'NetworkInformation'.ts(2430)
Also
The types of 'connection.type' are incompatible between these types.
Type 'string' is not assignable to type 'ConnectionType'.

What is expected to happen?

Typescript compilation completes without errors

What does actually happen?

Typescript compilation errors out

Information

None that seemed relevant

Command or Code

tsc

Environment, Platform, Device

Typescript Compilation

Version information

Typescript Version 4.5.4
cordova-plugin-network-information Version 3.0.0

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Differentiate between connections?

While using navigator['connection].type while connected to Verizon cellular 4g and local wifi, the plugin returns '4g' as the network type even though the device's preferred connection is wifi(which is the case for most devices). How can I differentiate/solve this? Thank you.

Connection error with Android 9

Bug Report

I´m this plugin with Sencha Ext 5.1.3 on app. My Android versión is 9.
I´m use barcode plugin too
My app is installed on Samsung Xcover 4 Devices.

Problem

Randomly the plugin returns connection error in the onOffline functions.
Samsung's technical service has reviewed the error and has verified (through its log tools) that internally the device does not lose Internet connection, so it has determined that it is an app error

What is expected to happen?

What does actually happen?

Information

Command or Code

Environment, Platform, Device

Version information

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

5G detect support

Feature Request

Motivation Behind Feature

Recently, a lot of device support 5G celluar. and some people need 5g support in this lib.

Feature Description

if connected network celluar is 5G, navigator.connection.type return '5G'.

Alternatives or Workarounds

nope.

I already know, this feature discuss in issues.
Is there any plan update this lib version what 5g detect feature attached?

XCode log: Permission denied for Signal strength query

The plugin basically does what it is supposed to do 👍 but I get an error in latest XCode 10 in the console log:

[NetworkInfo] Signal strength query returned error: Error Domain=NSPOSIXErrorDomain Code=13 "Permission denied", descriptor: <CTServiceDescriptor 0x283834d00, domain=1, instance=1>

Is this a known issue that I should ignore?

Error: Connection is not defined

I have installed the plugin correctly and it was working earlier. after few months, today I am trying to run the application on my phone and hitting with this error.

I do not see it reported by others yet so not sure if this is specific to my phone?
I am on Android 8.1.0, ColorOS Version v5.1

states[Connection.UNKNOWN] = 'Unknown connection';

stack: "ReferenceError: Connection is not defined
at eval (eval at checkConnection (file:///android_asset/www/js/index.js:560:5), <anonymous>:1:1)
at checkConnection (file:///android_asset/www/js/index.js:560:5)
at doLogin 

Network status not reliable

Bug Report

Problem

What is expected to happen?

I would expect this plugin always to reflect the true network status of a mobile device, being notified when the status changes with its proper value

What does actually happen?

In general it works fine, but at some point I get stuck with a notification indicating that there's no network connection while the mobile device actual does have a connection. It's hard to reproduce, most time it works fine but on some occasions it doesn't. I subscribe to both onConnect and onDisconnect events.

This provides a really bad user experience since there are many web services that are not being called depending on the network status (some others are cached locally since I try to provide offline support and then sync to the server when connection is back online), like the login web service.

I'm not sure if I should rely entirely on this plugin anymore or if I'm doing something wrong. Does anyone had this behavior? I've seen it mostly on Android devices.

Thanks in advance!

Information

networkplugin

I subscribe to the provided events by the plugin on a service I use across the application, and when they are fired I check the network type just in case.... but to double check I set a timeout of 2 seconds and then re-check the current network type. Only then I change the status based on the type. If by some reason a subsequent event is fired I clear the timeout to prevent this with messing with the current network status from the last fired event

Command or Code

 public online: boolean;
 private notify;

 constructor(private _pf: Platform, private _nw: Network) {
    this.initNetwork();
 }
 
 public initNetwork(){
	this._pf.ready().then(() => {
        if (this._pf.is('cordova')) {
	this._nw.onDisconnect().subscribe(() => {
		console.log('now type... ', this._nw.type);
		this.clearNetworkNotification();
		this.notify = setTimeout(() => {
			console.log('just to be sure.. ', this._nw.type);
			if (this._nw.type.toLowerCase() === 'none') {
			console.log('we are offline!');
			this.online = false;
			}
		}, 2000);
	});
	this._nw.onConnect().subscribe(() => {
		console.log('now type... ', this._nw.type);
		this.clearNetworkNotification();
		this.notify = setTimeout(() => {
			console.log('just to be sure.. ', this._nw.type);
			if (this._nw.type.toLowerCase() !== 'none') {
				console.log('we are online!');
				this.online = true;
			}
		}, 2000);
	});
        }
    });
 }
 
 private clearNetworkNotification() {
    if (this.notify) {
        clearTimeout(this.notify);
        this.notify = undefined;
    }
 }
 
 public getNetworkStatus(){
	return this.online;
 }

Environment, Platform, Device

I'm building an Ionic 4 application in Angular 7 with cordova

Version information

Ionic:

   Ionic CLI                     : 5.2.2 (C:\Users\rodrigomartinezjr\AppData\Roaming\npm\node_modules\ionic)
   Ionic Framework               : @ionic/angular 4.8.1
   @angular-devkit/build-angular : 0.12.4
   @angular-devkit/schematics    : 7.2.1
   @angular/cli                  : 7.3.0
   @ionic/angular-toolkit        : 1.3.0

Cordova:

   Cordova CLI       : 8.1.2 ([email protected])
   Cordova Platforms : not available
   Cordova Plugins   : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 4.1.3, (and 16 other plugins)

Utility:

   cordova-res : 0.6.0 
   native-run  : 0.2.7 

System:

   NodeJS : v10.14.1 (C:\Program Files\nodejs\node.exe)
   npm    : 6.4.1
   OS     : Windows 10
code-push 2.0.6 "CodePushAcquisition"
cordova-android-support-gradle-release 3.0.0 "cordova-android-support-gradle-release"
cordova-plugin-code-push 1.11.17 "CodePush"
cordova-plugin-compat 1.2.0 "Compat"
cordova-plugin-device 2.0.2 "Device"
cordova-plugin-dialogs 2.0.1 "Notification"
cordova-plugin-file 4.3.3 "File"
cordova-plugin-file-transfer 1.6.3 "File Transfer"
cordova-plugin-geolocation 4.0.1 "Geolocation"
cordova-plugin-globalization 1.11.0 "Globalization"
cordova-plugin-googlemaps 2.5.3 "cordova-plugin-googlemaps"
cordova-plugin-ionic-keyboard 2.1.3 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 4.1.3 "cordova-plugin-ionic-webview"
cordova-plugin-network-information 2.0.1 "Network Information"
cordova-plugin-request-location-accuracy 2.2.3 "Request Location Accuracy"
cordova-plugin-splashscreen 5.0.2 "Splashscreen"
cordova-plugin-statusbar 2.4.2 "StatusBar"
cordova-plugin-whitelist 1.3.3 "Whitelist"
cordova-plugin-zip 3.1.0 "cordova-plugin-zip"
cordova-sqlite-storage 3.2.0 "Cordova sqlite storage plugin - cordova-sqlite-storage plugin version"
cordova.plugins.diagnostic 5.0.1 "Diagnostic"
im.ltdev.cordova.UserAgent 1.0.1 "User-Agent"

Checklist

  • I searched for existing GitHub issues
  • I updated all Cordova tooling to most recent version
  • I included all the necessary information above

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.