WiFi
onWifiConnected
TIP
The API usage is as follows: wx.onWifiConnected(function listener)
TIP
Support:
- Android: Support
- iOS: Support
- Functional description: Listen for events connected to Wi-Fi
- Parameters and descriptions: function listener,Listener function for Wi-Fi connected events, parameter Object res is as follows:
Properties Type Description wifi WifiInfo Wi-Fi information
offWifiConnected
TIP
The API usage is as follows: wx.offWifiConnected(function listener)
Functional description: Remove listener function for events connected to Wi-Fi
Parameters and descriptions: function listener,Listener function passed in by onWifiConnected. If this parameter is not passed, all listening functions will be removed
Sample code:
const listener = function (res) { console.log(res) }
wx.onWifiConnected(listener)
wx.offWifiConnected(listener) // Pass the same function object used for listening.stopWifi
TIP
The API usage is as follows: wx.stopWifi(Object object)
Functional description: Turn off Wi-Fi module
Parameters and descriptions: Object object。
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Error code
Error code Error message Description 0 ok Normal 12000 not init The startWifi interface was not called first 12001 system not support The current system does not support related capabilities 12002 password error Wi-Fi Wrong password 12003 connection timeout Connection timeout, only supported by Android 12004 duplicate request Repeatedly connect to Wi-Fi 12005 wifi not turned on Android-specific, Wi-Fi switch is not turned on 12006 gps not turned on Android-specific, GPS positioning switch is not turned on 12007 user denied User refuses to authorize Wi-Fi connection 12008 invalid SSID Invalid SSID 12009 system config err System operator configuration refuses to connect to Wi-Fi 12010 system internal error Other system errors, the specific error reason needs to be printed in errmsg 12011 weapp in background The application cannot configure Wi-Fi in the background 12013 wifi config may be expired The Wi-Fi configuration saved by the system is expired, it is recommended to forget Wi-Fi and try again, only supported by Android 12014 invalid WEP / WPA password iOS-specific, invalid WEP / WPA password Sample code:
wx.stopWifi({
success (res) {
console.log(res.errMsg)
}
})startWifi
TIP
The API usage is as follows: wx.startWifi(Object object)
Functional description: Initialize Wi-Fi module
Parameters and descriptions: Object object。
Properties Type Default value Required Description success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) Error code
Error code Error message Description 0 ok Normal 12000 not init The startWifi interface was not called first 12001 system not support The current system does not support related capabilities 12002 password error Wi-Fi Wrong password 12003 connection timeout Connection timeout, only supported by Android 12004 duplicate request Repeatedly connect to Wi-Fi 12005 wifi not turned on Android-specific, Wi-Fi switch is not turned on 12006 gps not turned on Android-specific, GPS positioning switch is not turned on 12007 user denied User refuses to authorize Wi-Fi connection 12008 invalid SSID Invalid SSID 12009 system config err System operator configuration refuses to connect to Wi-Fi 12010 system internal error Other system errors, the specific error reason needs to be printed in errmsg 12011 weapp in background The application cannot configure Wi-Fi in the background 12013 wifi config may be expired The Wi-Fi configuration saved by the system is expired, it is recommended to forget Wi-Fi and try again, only supported by Android 12014 invalid WEP / WPA password iOS-specific, invalid WEP / WPA password Sample code:
wx.startWifi({
success (res) {
console.log(res.errMsg)
}
})onGetWifiList
TIP
The API usage is as follows: wx.onGetWifiList(function listener)
- Functional description: Listen for events of getting Wi-Fi list data
- Parameters and descriptions: function listener,Listening function for events that obtain Wi-Fi list data. Parameter Object res is as follows:
Properties Type Description wifiList Array.<WifiInfo> Wi-Fi list data
offGetWifiList
TIP
The API usage is as follows: wx.offGetWifiList(function listener)
Functional description: Remove listener function for events of getting Wi-Fi list data
Parameters and descriptions: function listener,Listening function passed in by onGetWifiList. If this parameter is not passed, all listening functions will be removed
Sample code:
const listener = function (res) { console.log(res) }
wx.onGetWifiList(listener)
wx.offGetWifiList(listener) // Pass the same function object used for listening.getConnectedWifi
TIP
The API usage is as follows: wx.getConnectedWifi(Object object)
Functional description: Get connected Wi-Fi information
Parameters and descriptions: Object object。
Properties Type Default value Required Description partialInfo boolean false No Do you need to return partial Wi-Fi information? success Function - No Callback function for successful interface call fail Function - No Callback function for failed interface call complete Function - No Callback function for interface call completion (executed regardless of success or failure) object.success callback function parameters: object res。
Properties Type Description wifi WifiInfo Wi-Fi information Error code
Error code Error message Description 0 ok Normal 12000 not init The startWifi interface was not called first 12001 system not support The current system does not support related capabilities 12002 password error Wi-Fi Wrong password 12003 connection timeout Connection timeout, only supported by Android 12004 duplicate request Repeatedly connect to Wi-Fi 12005 wifi not turned on Android-specific, Wi-Fi switch is not turned on 12006 gps not turned on Android-specific, GPS positioning switch is not turned on 12007 user denied User refuses to authorize Wi-Fi connection 12008 invalid SSID Invalid SSID 12009 system config err System operator configuration refuses to connect to Wi-Fi 12010 system internal error Other system errors, the specific error reason needs to be printed in errmsg 12011 weapp in background The application cannot configure Wi-Fi in the background 12013 wifi config may be expired The Wi-Fi configuration saved by the system is expired, it is recommended to forget Wi-Fi and try again, only supported by Android 12014 invalid WEP / WPA password iOS-specific, invalid WEP / WPA password
WifiInfo
- Functional description: Wifi information
TIP
- Android wx.connectWifi / wx.getConnectedWifi If partialInfo:true is set, or the wx.onWifiConnectedWithPartialInfo event is called, a WifiInfo object containing only the SSID attribute will be returned.
- iOS wx.getConnectedWifi If partialInfo:true is set, a WifiInfo object containing only the SSID and BSSID attributes will be returned, and the user needs to enable the host client location permission to return the result correctly
- In some cases, the Wi-Fi may have been successfully connected, but an error will be reported because the complete WifiInfo object cannot be obtained. The specific error message is errCode:12010, errMsg: can't gain current wifi or no wifi is connected. If the developer does not need a complete WifiInfo object, the error problem can be solved by adopting the above strategy
Properties
- string SSID: Wi-Fi SSID
- string BSSID: Wi-Fi BSSID
- boolean secure: Is Wi-Fi safe
- number signalStrength: Wi-Fi signal strength, Android takes values
- number frequency: Wi-Fi frequency band unit MHz