my.onNetworkStatusChange

Use this JSAPI to listen to the event of network status change. After the interface is called, listening is automatically started. The callback interval is 500ms. You can use my.offNetworkStatusChange to stop listening.

Sample Code

copy
Page({
    // callback function
    listener(res) {
        console.log(res);
    },
    // listen to the event of network status change
    onNetworkStatusChange() {
        my.onNetworkStatusChange(this.listener);
    },
});

Parameters

Property

Type

Required

Description

listener

Function

Yes

The callback function to listen to the event of network status change.

listener Callback Function

The incoming parameter is of the Object type with the following attributes:

Property

Type

Description

isConnected

Boolean

Indicates whether the network is connected.

networkType

String

Indicates the network type. Valid value:

  • UNKNOWN: The network type is unknown. For Android,If the client's permission to obtain phone information is set to "ask" or "deny", the return value is UNKNOWN.
  • NOTREACHABLE: The network is not available.
  • WWANWireless Wide Area Network
  • WIFI: Wifi nework
  • 2G2G network
  • 3G3G network
  • 4G4G network
  • 5G5G network

signalStrength

Number

Indicates the signal strength in "dbm" unit. This parameter is used only when the networkType is WIFI.

Note: This parameter is returned only for Android.

hasSystemProxy

Boolean

Indicates whether using the network proxy.