title: Taro.getNetworkType(option)
sidebar_label: getNetworkType
Gets the network type.
Reference
Type
(option?: Option) => Promise<SuccessCallbackResult>
Parameters
Option
Property |
Type |
Required |
Description |
complete |
(res: any) => void |
No |
The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail |
(res: any) => void |
No |
The callback function for a failed API call |
success |
(res: Result) => void |
No |
The callback function for a successful API call |
SuccessCallbackResult
Property |
Type |
Description |
networkType |
"wifi" | "2g" | "3g" | "4g" | "unknown" | "none" |
Network type |
errMsg |
string |
Call result |
networkType
Valid values of res.networkType
Property |
Description |
wifi |
wifi network |
2g |
2g network |
3g |
3g network |
4g |
4g network |
unknown |
Uncommon network types for Android |
none |
No network |
Sample Code
Taro.getNetworkType({
success: function (res) {
var networkType = res.networkType
}
})
API Support
API |
WeChat Mini-Program |
H5 |
React Native |
Taro.getNetworkType |
✔️ |
✔️ |
✔️ |