> 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.

# connectWifi

连接指定 Wi-Fi。

## 扫码预览

![扫码预览 connectWifi](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%252Fconnect-wifi%252Findex)

## 使用限制

> \[!WARNING]
> **iOS**：豆包 iOS 的连接实现不接收 bssid，仅按 ssid 与密码连接；iOS 上传入 bssid 不会生效。

## 支持版本

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

## 支持平台

<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 完成初始化

## 使用说明

通常先调用 startWifi。设置 manual 为 true 时会跳转到系统 Wi-Fi 设置页由用户手动连接。

- 连接过程由系统弹窗确认
- **iOS**：传入的 bssid 会被忽略，仅按 ssid 与 password 连接

## 调用方式

### 异步 API

```typescript
connectWifi(params: ConnectWifiParams): Promise<object>
```

## 入参

<table>
<thead>
<tr><th>名称</th><th>类型</th><th>必填</th><th>默认值</th><th>约束</th><th>说明</th></tr>
</thead>
<tbody>
<tr><td><code>bssid</code></td><td><code>string</code></td><td>否</td><td><code>-</code></td><td>仅 Android 使用，iOS 会忽略该字段</td><td>Wi-Fi BSSID。iOS：豆包 iOS 的连接实现不接收 bssid，仅按 ssid 与密码连接。</td></tr>
<tr><td><code>manual</code></td><td><code>boolean</code></td><td>否</td><td><code>false</code></td><td>-</td><td>是否跳转到系统设置页连接。</td></tr>
<tr><td><code>partialInfo</code></td><td><code>boolean</code></td><td>否</td><td><code>false</code></td><td>-</td><td>是否仅返回部分 Wi-Fi 信息。</td></tr>
<tr><td><code>password</code></td><td><code>string</code></td><td>是</td><td>-</td><td>-</td><td>Wi-Fi 密码。</td></tr>
<tr><td><code>ssid</code></td><td><code>string</code></td><td>是</td><td>-</td><td>-</td><td>Wi-Fi SSID。</td></tr>
</tbody>
</table>

## 调用示例

```typescript
import { connectWifi, startWifi } from '@doubao-dev/framework/api';

await startWifi();
await connectWifi({ ssid: 'Office-WiFi', password: 'password' });
```

## 成功返回

无返回字段。

### 返回示例

```json
{}
```

## 错误处理

错误对象和通用错误码见 [通用错误处理](/apps-plugin/docs/js-api/common-errors.md#错误返回)。

### 失败示例

```json
{
  "errNo": 1401003,
  "errMsg": "connect wifi failed"
}
```

### 错误码

<table>
<thead>
<tr><th>errNo</th><th>errMsg</th><th>平台</th><th>触发条件</th><th>处理建议</th></tr>
</thead>
<tbody>
<tr><td><code>104</code></td><td><code>invalid parameter</code></td><td>Android、iOS</td><td>ssid 为空</td><td>传入非空的 ssid 后重试</td></tr>
<tr><td><code>103</code></td><td><code>feature not support</code></td><td>Android、iOS</td><td>设备无可用的 Wi-Fi 能力，或 iOS 系统版本过低不支持连接</td><td>检查设备与系统能力，不支持时不要调用</td></tr>
<tr><td><code>1401001</code></td><td><code>wifi is not initialized</code></td><td>Android、iOS</td><td>调用前未先调用 startWifi 完成初始化</td><td>先调用 startWifi 再连接 Wi-Fi</td></tr>
<tr><td><code>115</code></td><td><code>operation timeout</code></td><td>Android</td><td>连接 Wi-Fi 超时</td><td>确认目标网络可用后提示用户重试</td></tr>
<tr><td><code>1401003</code></td><td><code>connect wifi failed</code></td><td>Android、iOS</td><td>连接目标 Wi-Fi 失败（如密码错误、网络不可达、系统连接被拒）</td><td>检查 ssid 与密码后提示用户重试</td></tr>
</tbody>
</table>

#### 通用错误码

<table>
<thead>
<tr><th>errNo</th><th>errMsg</th><th>说明</th><th>平台</th></tr>
</thead>
<tbody>
<tr><td><code>102</code></td><td><code>internal error</code></td><td>内部错误</td><td>Android、iOS</td></tr>
</tbody>
</table>

## 平台差异

- **Android**：连接超时返回 115；iOS 未细分超时，连接失败统一归为 1401003。
