快速入门
复制包含安装步骤和该插件完整 Markdown 指南的配置 prompt。
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-proximity`
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/proximity/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 skills 添加到你的 AI 工具中:
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-plugins然后使用以下 prompt:
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-proximity` plugin in my project.如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:
bun add @capgo/capacitor-proximitybunx cap sync导入
“导入”章节import { CapacitorProximity } from '@capgo/capacitor-proximity';快速入门
章节标题为“快速入门”import { CapacitorProximity } from '@capgo/capacitor-proximity';
const { available } = await CapacitorProximity.getStatus();if (!available) return;
await CapacitorProximity.enable();// start VoIP or voice playback UI示例:语音消息播放
标题为“示例:语音留言播放”的章节await CapacitorProximity.enable();await playVoiceNote();await CapacitorProximity.disable();常见坑点
章节标题为“常见陷阱”- 始终禁用: 调用
disable()中的finally阻止亮度在错误后恢复。 - 无传感器设备:检查
getStatus()在显示耳部接近 UX 之前。 - Web 端:接近 API 未暴露,仅保留原生调用。
API 概览
章节标题:“API 概览”enable
标题为“enable”的章节启用距离感应监控。
在 iOS 上,这会启用 UIDevice.isProximityMonitoringEnabled。
在 Android 上,这会开始监听 TYPE_PROXIMITY ,并在传感器被遮挡时调暗当前应用窗口。
import { CapacitorProximity } from '@capgo/capacitor-proximity';
await CapacitorProximity.enable();disable
标题为“disable”的章节禁用距离感应监控。
这将恢复默认的应用窗口行为,并停止传感器监控。
import { CapacitorProximity } from '@capgo/capacitor-proximity';
await CapacitorProximity.disable();getStatus
标题为“getStatus”的章节获取当前传感器可用性及插件启用状态。
import { CapacitorProximity } from '@capgo/capacitor-proximity';
const status = await CapacitorProximity.getStatus();类型参考
“类型参考” 章节ProximityStatusResult
标题为“ProximityStatusResult”的章节返回结果: getStatus().
export interface ProximityStatusResult { /** * Whether the current device exposes a usable proximity sensor. * * @since 0.0.1 */ available: boolean;
/** * Whether proximity monitoring is currently enabled by the plugin. * * @since 0.0.1 */ enabled: boolean;
/** * Platform label returned by the native or web implementation. * * @since 0.0.1 */ platform: 'ios' | 'android' | 'web';}PluginVersionResult
标题为“PluginVersionResult”的章节请求插件版本时返回的结果。
export interface PluginVersionResult { /** * Native plugin version string. * * @since 0.0.1 */ version: string;}单一事实来源
标题为“单一事实来源”的部分本页面由插件的 src/definitions.ts生成。当上游的公共 API 发生变化时,请重新运行 sync。
从入门指南继续
“从入门指南继续”章节如果你正在使用 快速入门 要规划 dashboard 和 API 操作,请将其连接到 使用 @capgo/capacitor-proximity 在“使用 @capgo/capacitor-proximity”中的原生功能 API 概览 关于 API Overview 中的实现细节, 简介 关于 Introduction 中的实现细节, API 密钥 有关 API Keys 的实现细节,以及 设备 有关 Devices 的实现细节。