my.getNetworkType
This API is supported in mPaaS 10.1.32 and later versions.
This API is used to get the current network status.
Input parameter
Name | Type | Required | Description |
---|---|---|---|
success | Function | No | Callback function for successful call |
fail | Function | No | Callback function for failed call |
complete | Function | No | Callback function for ended call (executed regardless of whether the call is successful or failed) |
success return value
Name | Type | Description |
---|---|---|
networkAvailable | Boolean | Whether the network is available |
networkType | String | The possible network type values are UNKNOWN/NOTREACHABLE/WIFI/3G/2G/4G/WWAN |
Code sample
Page({
data: {
hasNetworkType: false
},
getNetworkType() {
my.getNetworkType({
success: (res) => {
this.setData({
hasNetworkType: true,
networkType: res.networkType
})
}
})
},
clear() {
this.setData({
hasNetworkType: false,
networkType: ''
})
},
});
my.onNetworkStatusChange(CALLBACK)
This API is supported in mPaaS 10.1.32 and later versions.
Start monitoring changes in network status.
Return value
Name | Type | Description |
---|---|---|
isConnected | Boolean | Whether the network is available |
networkType | String | The possible network type values are UNKNOWN/NOTREACHABLE/WIFI/3G/2G/4G/WWAN |
Code sample
my.onNetworkStatusChange(function(res){
console.log(JSON.stringify(res))
})
my.offNetworkStatusChange
This API is supported in mPaaS 10.1.32 and later versions.
Cancel monitoring changes in network status.
Code sample
my.offNetworkStatusChange()
Whether to pass the callback value
- If the callback value is not passed, all event callbacks will be removed. The code sample is as follows:
my.offNetworkStatusChange();
- If the callback value is passed, only remove the corresponding callback event. The code sample is as follows:
my.offNetworkStatusChange(this.callback);