my.getNetworkType
Get the current network status.
Sample Code
copy
Page({
data: {
hasNetworkType: false
},
getNetworkType() {
my.getNetworkType({
success: (res) => {
this.setData({
hasNetworkType: true,
networkType: res.networkType
})
}
})
},
clear() {
this.setData({
hasNetworkType: false,
networkType: ''
})
},
});
Parameters
Property | Type | Required | Description |
success | Function | No | Callback function upon call success. |
fail | Function | No | Callback function upon call failure. |
complete | Function | No | Callback function upon call completion (to be executed upon either call success or failure). |
Success Callback Function
The incoming parameter is of the Object type with the following attributes:
Property | Type | Description |
networkAvailable | Boolean | If the network is available. |
networkType | String | Network type, UNKNOWN / NOTREACHABLE / WIFI / 3G / 2G / 4G / 5G/ WWAN. |