Wi-Fi function module

The App platform is implemented by uni ext api, you need to download the plug-in: [uni-WiFi](https://ext.dcloud.net. cn/plugin?id=10337)

uni ext api requires HBuilderX 3.6.8+

iOS平台获取Wi-Fi信息需要开启“Access WiFi information”能力登录苹果开发者网站,在“Certificates, Identifiers & Profiles”页面选择“Identifiers”中选择对应的App ID,确保开启“Access WiFi information”,保存后重新生成profile文件。

iOS平台iOS13及以上系统,获取当前连接的Wi-Fi信息需要先获取系统定位权限,因此在iOS13及以上系统使用此接口时,会触发定位权限申请的弹窗。

The development methods of other platforms are not yet unified. When using it, you should pay attention to using conditional compilation to call codes of different platforms.

WeChat Mini Program Platform Implementation Reference: Specification Details

Baidu Smart Mini Program Platform Implementation Reference: Specification Details

抖音小程序的wifi API参考:规范详情

# uni.startWifi(OBJECT)

Initialize the Wi-Fi module

OBJECT parameter description

Parameter Name Type Required Description
success function No Callback function for successful interface call
fail function No Callback function for interface call failure
complete function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

# uni.stopWifi(OBJECT)

Turn off the Wi-Fi module

OBJECT parameter description

Parameter Name Type Required Description
success function No Callback function for successful interface call
fail function No Callback function for interface call failure
complete function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

# uni.getConnectedWifi(OBJECT)

Get connected Wi-Fi information

OBJECT parameter description

Property Type Default Value Required Description
partialInfo boolean false No Whether partial Wi-Fi information should be returned
success function No Callback function for successful interface call
fail function No Callback function for interface call failure
complete function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

success return parameter description

Parameter Type Description
wifi WifiInfo Wi-Fi Information

# uni.getWifiList(OBJECT)

Request a Wi-Fi list. The wifiList data will be returned in the callback registered by onGetWifiList.

OBJECT parameter description

Attribute Type Required Description
success function No Callback function for successful interface call
fail function No Callback function for interface call failure
complete function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

Platform Difference Description

App-Android App-iOS
x

# uni.onGetWifiList(CALLBACK)

Listen to the event of getting Wi-Fi list data.

CALLBACK parameter description

Obtain the listener function of the Wi-Fi list data event

CALLBACK return parameter

Property Type Description
wifiList Array<WifiInfo> Wi-Fi 列表数据

Platform Difference Description

App-Android App-iOS
x

# uni.offGetWifiList(CALLBACK)

Remove the listener function for getting the Wi-Fi list data event.

CALLBACK parameter description

The listener function passed in by onGetWifiList. If this parameter is not passed, all listener functions will be removed.

Platform Difference Description

App-Android App-iOS
x

# uni.connectWifi(OBJECT)

Connect to Wi-Fi. If the Wi-Fi information is known, you can directly use this interface to connect.

OBJECT parameter description

Property Type Default Required Description Minimum Version
SSID string yes Wi-Fi device SSID
BSSID string No Wi-Fi Device BSSID
password string yes Wi-Fi device password
maunal boolean false no jump to the system settings page to connect 2.12.0
partialInfo boolean false No Whether to return partial Wi-Fi information, only valid for Android 2.22.0
success function No Callback function for successful interface call
fail function No Callback function for interface call failure
complete function No The callback function for the end of the interface call (it will be executed when the call succeeds or fails)

Platform Difference Description

App-Android App-iOS
android10 以下版本支持直连,android 10以上,包括鸿蒙系统仅支持 maunal 手动链接 x

# uni.onWifiConnected(CALLBACK)

Listen for Wi-Fi connected events.

CALLBACK parameter description

Listener function for events connected to Wi-Fi

CALLBACK return parameter

Property Type Description
wifi WifiInfo Wi-Fi 信息

Platform Difference Description

App-Android App-iOS
x

# uni.offWifiConnected(CALLBACK)

Remove the listener function for events connected to Wi-Fi.

CALLBACK parameter description

onWifiConnected incoming listener function. If this parameter is not passed, all listener functions will be removed.

Platform Difference Description

App-Android App-iOS
x

# uni.onWifiConnectedWithPartialInfo(CALLBACK)

Listen for Wi-Fi connected events.

CALLBACK parameter description

Listener function for events connected to Wi-Fi

CALLBACK return parameter

Property Type Description
wifi WifiInfo 只包含 SSID 属性的 WifiInfo 对象

Platform Difference Description

App-Android App-iOS
x

# uni.offWifiConnectedWithPartialInfo(CALLBACK)

Remove the listener function for events connected to Wi-Fi.

CALLBACK parameter description

onWifiConnectedWithPartialInfo The listener function passed in. If this parameter is not passed, all listener functions will be removed.

Platform Difference Description

App-Android App-iOS
x

# WifiInfo

WiFi information

Property Type Description
SSID string SSID for Wi-Fi
BSSID string BSSID for Wi-Fi
secure boolean Is the Wi-Fi secure
signalStrength number Wi-Fi signal strength, Android value 0 ~ 100
frequency number Wi-Fi frequency band unit MHz

# error code

Error code Error message Description
0 ok normal
12000 not init did not call the startWifi interface first
12001 system not support The current system does not support the relevant capabilities
12002 password error Wi-Fi password error
12005 wifi not turned on Android specific, Wi-Fi switch not turned on
12013 wifi config may be expired The Wi-Fi configuration saved by the system has expired. It is recommended to forget the Wi-Fi and try again. Only Android supports

# refer to