开始使用
复制一个包含安装步骤和本插件的完整Markdown指南的设置提示
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-uwb`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/uwb/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
安装
标题为“安装”您可以使用我们的 AI 助手设置来安装插件。将 Capgo 技能添加到您的 AI 工具中,使用以下命令:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下提示:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-uwb` plugin in my project.如果您更喜欢手动设置,请按照以下命令安装插件并遵循以下平台特定的说明:
bun add @capgo/capacitor-uwbbunx cap sync导入
导入import { CapacitorUwb } from '@capgo/capacitor-uwb';检查可用性
检查可用性const availability = await CapacitorUwb.isAvailable();
if (!availability.supported) { console.log('This device does not support UWB.');}iOS 设备会话
iOS 设备会话- 拨打
getDiscoveryToken()在两台设备上 - 交换返回的base64令牌。
- 使用对等令牌开始测距。
const { discoveryToken } = await CapacitorUwb.getDiscoveryToken();
await CapacitorUwb.startPeerSession({ peerDiscoveryToken: '<peer-token-base64>',});查看 iOS设置 查看能力和权限要求。
Android控制器/控制对象会话
Android控制器/控制对象会话- 控制器调用
startControllerSession()并共享返回的rangingParameters并localAddress. - 控制对象自己构建
rangingParameters使用控制器localAddress作为peerAddress. - 控制者调用
startControleeSession({ rangingParameters }). - 可选地将
peerAddress传递给控制器一旦控制者地址已知。
const controller = await CapacitorUwb.startControllerSession();
await CapacitorUwb.startControleeSession({ rangingParameters: { ...controller.rangingParameters, peerAddress: controller.localAddress, },});参见 安卓设置 硬件和权限要求。
监听更新
标题:监听更新await CapacitorUwb.addListener('rangingUpdate', (event) => { console.log(event.distanceMeters, event.direction);});
await CapacitorUwb.addListener('sessionStateChanged', (event) => { console.log(event.state, event.reason);});停止会话
标题:停止会话await CapacitorUwb.stopSession();真实来源
标题:真实来源本页面由插件生成 src/definitions.ts更新 TypeScript 定义并运行 bun run docgen in the plugin repository to refresh the generated API docs.