WeChat Open Platform

Mini Programs Documentation

Network Status

wx.getNetworkType(OBJECT)

Gets network type.

OBJECT parameter descriptions:

Parameter Type Required Description
success Function Yes Successful interface call, network type networkType returned
fail Function No Callback function for failed interface call
complete Function No Callback function for interface call results (will be executed if call succeeds or fails)

success return parameter descriptions:

Parameter Description
networkType Network type
wx.getNetworkType({
  success: function(res) {
    // Returns network type, valid values:
    // wifi/2g/3g/4g/unknown(uncommon network type under Android)/none(no network)
    var networkType = res.networkType
  }
})

wx.onNetworkStatusChange(CALLBACK)

Monitors changes to network status.

CALLBACK return parameters:

Parameter Type Description
isConnected Boolean Whether there is currently a network connection
networkType String Network type

networkType valid values:

Value Description
wifi Wi-Fi 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)
})