开始使用
复制一个包含安装步骤和本插件的完整 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. - The controlled device builds its own
rangingParameters, using the controllerlocalAddressaspeerAddress. - The controlled device calls
startControleeSession({ rangingParameters }). - Optionally pass
peerAddressto the controller once the controlled device address is known.
const controller = await CapacitorUwb.startControllerSession();
await CapacitorUwb.startControleeSession({ rangingParameters: { ...controller.rangingParameters, peerAddress: controller.localAddress, },});See Android setup for hardware and permission requirements.
Listen For Updates
Listen For Updatesawait 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.