tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-04-10 18:18:36
Network
Last updated: 2025-04-10 18:18:36

onNetworkStatusChange

This API is used via wx.onNetworkStatusChange(function callback).
Feature Description: function callback, a callback function for network state change events.
Parameter and Description: Function callback.
Callback function parameters for network status change events: Object res.
Attribute
Type
Description
isConnected
boolean
Current Network Connection Status
networkType
string
Network type
Legitimate Values of Legitimate
Value
Description
wifi
Wi-Fi Network
2g
2G Network
3g
3G Network
4g
4G Network
unknown
Uncommon Network Types on Android
none
No network
Sample Code
wx.onNetworkStatusChange(function (res) {
console.log(res.isConnected)
console.log(res.networkType)
})

getNetworkType

This API is used via wx.getNetworkType(Object object).
Feature Description: Gets the network type.
Parameter and Description: Object.
Attribute
Type
Default value
Required
Description
success
function
-
No
Callback Function of Successful Interface Call
fail
function
-
No
Callback Function of Failing Interface Call
complete
function
-
No
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Object.success callback function: Object res.
Attribute
Type
Description
networkType
string
Network type
Valid values of res.networkType
Value
Description
wifi
Wi-Fi Network
2g
2G Network
3g
3G Network
4g
4G Network
unknown
Uncommon Network Types on Android
none
No network
Sample Code
wx.getNetworkType({
success(res) {
const networkType = res.networkType
}
})

offNetworkStatusChange

This API is used via wx.offNetworkStatusChange(function listener).
Feature Description: Removes the listener function for network status change events.
Parameter and Description: function listener, the listener function passed in by onNetworkStatusChange. If this parameter is not passed in, all listener functions will be removed.
Sample Code
const listener = function (res) { console.log(res) }

wx.onNetworkStatusChange(listener)
wx.offNetworkStatusChange(listener) // The same function object as the listener must be passed in.

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback

Contact Us

Contact our sales team or business advisors to help your business.

Technical Support

Open a ticket if you're looking for further assistance. Our Ticket is 7x24 available.

7x24 Phone Support