Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

WeChat Small Program API-Device-Network State


May 19, 2021 WeChat Mini Program Development Document


Table of contents


wx.getNetworkType(OBJECT)

Get a network type.

Object parameter description:

parameter type Required illustrate
success Function Yes The interface call is successful, return to the network type networkType
fail Function no Interface call failed callback function
complete Function no The callback function ended in the interface call (the call is successful, failed)

SUCCESS Return Parameter Description:

parameter illustrate
networkType Network Type
wx.getNetworkType({
  success: function(res) {
    // 返回网络类型, 有效值:
    // wifi/2g/3g/4g/unknown(Android下不常见的网络类型)/none(无网络)
    var networkType = res.networkType
  }
})

wx.onNetworkStatusChange(CALLBACK)

The base library 1.1.0 began support, low version needs to be done Compatibility

Listen to network status changes.

Callback returns the parameters:

parameter type illustrate
isConnected Boolean Whether there is a network connection
networkType String Network Type

NetWorktype Valid value:

value illustrate
wifi WiFi network
2g 2G network
3g 3G network
4g 4G network
none No network
unknown Uncommon network type under Android

Sample code:

wx.onNetworkStatusChange(function(res) {
  console.log(res.isConnected)
  console.log(res.networkType)
})

wx.offNetworkStatusChange(function callback)

Base Library 2.9.3 starts to support, and low versions need to be compatible.

Cancel all event monitoring events with empty parameters.

Parameters

function callback

The callback function for network state change events