doc(readme): improve badges (#175)
- Added badges for npm version, git version, node ci workflow, release audit workflow
- Add cordova-doc build metadata comment
Co-authored-by: エリス erisu@users.noreply.github.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802032778号
cordova-docs build metadata
title: Network Information description: Get information about wireless connectivity.
cordova-plugin-network-information
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.
Installation
Supported Platforms
Connection
Properties
Constants
connection.type
This property offers a fast way to determine the device’s network connection state, and type of connection.
Quick Example
iOS Quirks
navigator.connection.typeis set toConnection.CELLfor all cellular data.Windows Quirks
navigator.connection.typeasConnection.ETHERNET.Browser Quirks
navigator.connection.typeis always set toConnection.UNKNOWNwhen online.Network-related Events
offline
The event fires when an application goes offline, and the device is not connected to the Internet.
Details
The
offlineevent 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 ofconnection.typebecomesNONE.Applications typically should use
document.addEventListenerto attach an event listener once thedevicereadyevent fires.Quick Example
Quirks
This plugin is unable to broadcast events while in the background. Use
navigator.connection.typeto 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.
Details
The
onlineevent 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 theconnection.typechanges fromNONEto any other value.Applications typically should use
document.addEventListenerto attach an event listener once thedevicereadyevent fires.Quick Example
Quirks
This plugin is unable to broadcast events while in the background. Use
navigator.connection.typeto check connection status on the resume event instead.iOS Quirks
During initial startup, the first
onlineevent (if applicable) takes at least a second to fire, prior to whichconnection.typeisUNKNOWN.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
devicereadyhandler.Next, add listeners for the online and offline events in the
devicereadyhandler.The app’s
onOnlinefunction 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.When the online event fires in the preceding code, call the app’s
tryToUploadFilefunction.If the upload fails, then call the app’s
offlineWritefunction to save the current data somewhere.Here is the code for the
offlineWritefunction.If the offline event occurs, just do something like notify the user (for this example, just log it).