Skip to main content
Version: 3.x

Taro.getNetworkType(option)

Gets the network type.

Reference

Type

(option?: Option) => Promise<SuccessCallbackResult>

Parameters

Option

PropertyTypeRequiredDescription
complete(res: any) => voidNoThe callback function used when the API call completed (always executed whether the call succeeds or fails)
fail(res: any) => voidNoThe callback function for a failed API call
success(res: Result) => voidNoThe callback function for a successful API call

SuccessCallbackResult

PropertyTypeDescription
networkType"wifi" | "2g" | "3g" | "4g" | "unknown" | "none"Network type
errMsgstringCall result

networkType

Valid values of res.networkType

PropertyDescription
wifiwifi network
2g2g network
3g3g network
4g4g network
unknownUncommon network types for Android
noneNo network

Sample Code

Taro.getNetworkType({
success: function (res) {
var networkType = res.networkType
}
})

API Support

APIWeChat Mini-ProgramH5React Native
Taro.getNetworkType✔️✔️✔️