> For AI agents: the complete documentation index is available at /apps-plugin/docs/llms.txt, the full documentation bundle is available at /apps-plugin/docs/llms-full.txt.

# onWifiConnected

监听连接上 Wi-Fi 的事件。

## 扫码预览

![扫码预览 onWifiConnected](https://api.qrserver.com/v1/create-qr-code/?size=200x200\&data=doubao%3A%2F%2Fdoubao_apps%3Fapp_id%3Ddb_1McM5Ni%26path%3D%252Fpages%252Fapi%252Fdevice%252Fwifi-lifecycle%252Findex)

## 支持版本

前端库版本不低于 `0.0.31`。

## 支持平台

<table>
<thead>
<tr><th>平台</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>Android</td><td>支持</td></tr>
<tr><td>iOS</td><td>支持</td></tr>
<tr><td>PC</td><td>不支持</td></tr>
<tr><td>HarmonyOS</td><td>不支持</td></tr>
</tbody>
</table>

## 支持场景

<table>
<thead>
<tr><th>场景</th><th>支持情况</th></tr>
</thead>
<tbody>
<tr><td>页面</td><td>支持</td></tr>
<tr><td>卡片</td><td>不支持</td></tr>
</tbody>
</table>

## 接入准备

### 前置条件

- 需先调用 startWifi 完成初始化

## 调用方式

### 事件监听 API

```typescript
onWifiConnected(callback: (event: WifiConnectedEvent) => void): () => void
```

## 入参

无。

## 调用示例

```ts
import { onWifiConnected } from '@doubao-dev/framework/api';

const off = onWifiConnected(({ wifi }) => {
  console.log(wifi.ssid);
});

off();
```

## 回调参数

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必返</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>event.wifi</code></td><td><code>WifiInfo</code></td><td>是</td><td>已连接的 Wi-Fi 信息。</td></tr>
<tr><td><code>event.wifi.bssid</code></td><td><code>string</code></td><td>否</td><td>Wi-Fi BSSID。</td></tr>
<tr><td><code>event.wifi.frequency</code></td><td><code>number</code></td><td>否</td><td>频段，单位 MHz。</td></tr>
<tr><td><code>event.wifi.secure</code></td><td><code>boolean</code></td><td>否</td><td>Wi-Fi 是否安全。</td></tr>
<tr><td><code>event.wifi.signalStrength</code></td><td><code>number</code></td><td>否</td><td>信号强度。</td></tr>
<tr><td><code>event.wifi.ssid</code></td><td><code>string</code></td><td>是</td><td>Wi-Fi SSID。</td></tr>
</tbody>
</table>

## 返回值

返回取消当前监听函数的函数。

### 回调示例

```json
{
  "wifi": {
    "ssid": "Office-WiFi",
    "bssid": "a0:b1:c2:d3:e4:f5",
    "secure": true
  }
}
```
