tencent cloud

All product documents
Tencent Cloud Super App as a Service
Last updated: 2025-03-25 18:15:55
WiFi
Last updated: 2025-03-25 18:15:55

onWifiConnected

The method of utilizing this API is wx.onWifiConnected(function listener).
Note:
Compatibility:
Android: Supported.
iOS: Supported.
Function Description: Monitors the event of connecting to a Wi-Fi network.
Parameters and Description: function listener, the listener function for the event of connecting to Wi-Fi, with the following arguments Object res:
Attributes
Types
Note
wifi
WifiInfo
Wi-Fi Information

offWifiConnected

The method of utilizing this API is wx.onWifiConnected(function listener).
Function Description: Monitors the event of connecting to a Wi-Fi network.
Parameters and Description: function listener, onWifiConnected The listener function passed in. Not passing this parameter removes all listener functions.
Attributes
Types
Note
wifi
WifiInfo
Wi-Fi Information
Sample code
const listener = function (res) { console.log(res) }

wx.onWifiConnected(listener)
wx.offWifiConnected(listener) // Pass in the same function object as the listener.

stopWifi

The usage method for this API is wx.stopWifi(Object object)
Function Description: Deactivates the Wi-Fi module.
Parameters and Description: Object object.
Attributes
Types
Default value
Required
Note
success
function
-
Not required
Callback function for successful interface invocation
fail
function
-
Not required
Callback function for unsuccessful interface invocation
complete
function
-
Not required
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Error Code
Error Codes
Error Message
Note
0
ok
Normal
12000
not init
The startWifi interface was not invoked beforehand.
12001
system not support
The current system does not support the relevant capabilities.
12002
password error Wi-Fi
The password is incorrect.
12003
connection timeout
Connection timeout, supported only on Android.
12004
duplicate request
Repeated connection to Wi-Fi.
12005
wifi not turned on
Exclusive to Android, the Wi-Fi switch has not been turned on.
12006
gps not turned on
Exclusive to Android, the GPS location switch has not been turned on.
12007
user denied
The user has denied authorization to connect to Wi-Fi.
12008
invalid SSID
Invalid SSID.
12009
system config err
The system operator configuration has denied the connection to Wi-Fi.
12010
system internal error
System miscellaneous error, it is necessary to print the specific error reason in errmsg.
12011
weapp in background
The application is unable to configure Wi-Fi while running in the background.
12013
wifi config may be expired
The system's saved Wi-Fi configuration has expired. It is recommended to forget the Wi-Fi and retry. This is only supported on Android.
12014
invalid WEP / WPA password
Specific to iOS, the WEP/WPA password is invalid.
Example Code
wx.stopWifi({
success (res) {
console.log(res.errMsg)
}
})

startWifi

The usage method for this API is wx.startWifi(Object object).
Function Description: Initializes the Wi-Fi module.
Parameters and Description: Object object.
Attributes
Types
Default value
Required
Note
success
function
-
Not required
Callback function for successful interface invocation
fail
function
-
Not required
Callback function for unsuccessful interface invocation
complete
function
-
Not required
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
Error Code
Error Codes
Error Message
Note
0
ok
Normal
12000
not init
The startWifi interface was not invoked beforehand.
12001
system not support
The current system does not support the relevant capabilities.
12002
password error Wi-Fi
The password is incorrect.
12003
connection timeout
Connection timeout, supported only on Android.
12004
duplicate request
Repeated connection to Wi-Fi.
12005
wifi not turned on
Exclusive to Android, the Wi-Fi switch has not been turned on.
12006
gps not turned on
Exclusive to Android, the GPS location switch has not been turned on.
12007
user denied
The user has denied authorization to connect to Wi-Fi.
12008
invalid SSID
Invalid SSID.
12009
system config err
The system operator configuration has denied the connection to Wi-Fi.
12010
system internal error
System miscellaneous error, it is necessary to print the specific error reason in errmsg.
12011
weapp in background
The application is unable to configure Wi-Fi while running in the background.
12013
wifi config may be expired
The system's saved Wi-Fi configuration has expired. It is recommended to forget the Wi-Fi and retry. This is only supported on Android.
12014
invalid WEP / WPA password
Specific to iOS, the WEP/WPA password is invalid.
Example Code
wx.startWifi({
success (res) {
console.log(res.errMsg)
}
})

onGetWifiList

The usage method for this API is wx.onGetWifiList(function listener).
Function Description: Monitors the event of receiving Wi-Fi list data.
Parameters and Description: Object res parameter, function listener, the monitoring function for the event of receiving Wi-Fi list data.
Attributes
Types
Note
wifiList
Array.<WifiInfo>
Wi-Fi List Data

offGetWifiList

The usage method for this API is wx.offGetWifiList(function listener).
Function Description: Removes the monitoring function for the event of receiving Wi-Fi list data.
Parameters and Description: Function listener, the monitoring function passed into onGetWifiList. If this parameter is not provided, all monitoring functions will be removed.
Sample code
const listener = function (res) { console.log(res) }

wx.onWifiConnected(listener)
wx.offWifiConnected(listener) // Pass in the same function object as the listener.

getConnectedWifi

The usage method for this API is wx.getConnectedWifi(Object object).
Function Description: Retrieves information about the currently connected Wi-Fi.
Parameters and Description: Object object
Attributes
Types
Default value
Required
Note
partialInfo
boolean
false
Not required
Whether partial Wi-Fi information needs to be returned.
success
function
-
Not required
Callback function for successful interface invocation
fail
function
-
Not required
Callback function for unsuccessful interface invocation
complete
function
-
Not required
Callback function executed upon the completion of the interface invocation (both successful and unsuccessful invocations)
object.success Callback Function Parameters: Object res
Attributes
Types
Note
wifi
WifiInfo
Wi-Fi Information
Error Code
Error Codes
Error Message
Note
0
ok
Normal
12000
not init
The startWifi interface was not invoked beforehand.
12001
system not support
The current system does not support the relevant capabilities.
12002
password error Wi-Fi
The password is incorrect.
12003
connection timeout
Connection timeout, supported only on Android.
12004
duplicate request
Repeated connection to Wi-Fi.
12005
wifi not turned on
Exclusive to Android, the Wi-Fi switch has not been turned on.
12006
gps not turned on
Exclusive to Android, the GPS location switch has not been turned on.
12007
user denied
The user has denied authorization to connect to Wi-Fi.
12008
invalid SSID
Invalid SSID.
12009
system config err
The system operator configuration has denied the connection to Wi-Fi.
12010
system internal error
System miscellaneous error, it is necessary to print the specific error reason in errmsg.
12011
weapp in background
The application is unable to configure Wi-Fi while running in the background.
12013
wifi config may be expired
The system's saved Wi-Fi configuration has expired. It is recommended to forget the Wi-Fi and retry. This is only supported on Android.
12014
invalid WEP / WPA password
Specific to iOS, the WEP/WPA password is invalid.

WifiInfo

Function Description: Wi-Fi Information.
Note:
For Android wx.connectWifi / wx.getConnectedWifi, if partialInfo:true is set, or if the wx.onWifiConnectedWithPartialInfo event is called, a WifiInfo object containing only the SSID property will be returned.
For iOS wx.getConnectedWifi, if partialInfo:true is set, a WifiInfo object containing only the SSID and BSSID properties will be returned. However, the user must enable the host client's location permissions for the results to be correctly returned.
In certain circumstances, even though the Wi-Fi may have successfully connected, an error may occur due to the inability to obtain a complete WifiInfo object. The specific error messages are errCode:12010, errMsg: can't gain current wifi or no wifi is connected. If developers do not require a complete WifiInfo object, they can resolve the error issue by adopting the aforementioned strategy.

Attributes

string SSID: The SSID of the Wi-Fi.
string BSSID: The BSSID of the Wi-Fi.
boolean secure: The security status of the Wi-Fi.
number signalStrength: The signal strength of the Wi-Fi. For Android, the value ranges from 0 to 100, while for iOS, the value ranges from 0 to 1. The larger the value, the stronger the signal strength.
number frequency: The frequency band of the Wi-Fi, measured in MHz.
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