Getting Started
复制一个包含安装步骤和本插件的完整Markdown指南的设置命令.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-auto`
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/auto/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.
-
安装包
终端窗口 npm i @capgo/capacitor-auto -
同步原生项目
终端窗口 npx cap sync -
设置根级车模板
import { Auto } from '@capgo/capacitor-auto';await Auto.setRootTemplate({title: 'Garage',sections: [{header: 'Doors',items: [{id: 'open-main-door',title: 'Open main door',subtitle: 'Tap to send the action to the phone app',payload: { doorId: 'main' },},],},],}); -
处理车辆操作
await Auto.addListener('carAction', async (event) => {if (event.id === 'open-main-door') {await openGarageDoor(event.payload?.doorId);}}); -
跟踪连接状态
const status = await Auto.isAvailable();console.log(status.available, status.connected, status.platform);await Auto.addListener('connectionChanged', (event) => {console.log('Car connected:', event.connected, event.platform);});
空状态
空状态设置 emptyText 模板无行时:
await Auto.setRootTemplate({ title: 'Garage', emptyText: 'No actions are available right now.', sections: [],});发送桥接消息
空状态用于应用定义的本地桥接消息: sendMessage 复制到剪贴板
await Auto.sendMessage({ type: 'status', payload: { online: true },});空状态
空状态继续从Getting Started
如果您正在使用Getting Started 来规划原生插件工作,连接它与 使用@__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-auto @capgo/capacitor-auto 为使用 @capgo/capacitor-auto 原生能力 Capgo 插件目录 为 Capgo 插件目录中的产品流程 Capacitor 由 Capgo 提供的插件 为 Capacitor 由 Capgo 提供的插件中的实现细节 添加或更新插件 为添加或更新插件中的实现细节 Ionic 企业插件替代方案 为 Ionic 企业插件替代方案中的产品流程