跳过内容

开始使用

GitHub

您可以使用我们的 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-uwb
bunx 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 设备会话
  1. 拨打 getDiscoveryToken() 在两台设备上
  2. 交换返回的base64令牌。
  3. 使用对等令牌开始测距。
const { discoveryToken } = await CapacitorUwb.getDiscoveryToken();
await CapacitorUwb.startPeerSession({
peerDiscoveryToken: '<peer-token-base64>',
});

查看 iOS设置 查看能力和权限要求。

Android控制器/控制对象会话

Android控制器/控制对象会话
  1. 控制器调用 startControllerSession() 并共享返回的 rangingParameterslocalAddress.
  2. 控制对象自己构建 rangingParameters使用控制器 localAddress 作为 peerAddress.
  3. 控制者调用 startControleeSession({ rangingParameters }).
  4. 可选地将 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.