跳过内容

Getting Started

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-auto` plugin in my project.

如果您更喜欢手动设置,请按照以下命令安装插件,并按照下面的平台特定说明进行操作:

  1. 安装包

    终端窗口
    npm i @capgo/capacitor-auto
  2. 同步本机项目

    终端窗口
    npx cap sync
  3. 设置根car模板

    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' },
    },
    ],
    },
    ],
    });
  4. 处理汽车操作

    await Auto.addListener('carAction', async (event) => {
    if (event.id === 'open-main-door') {
    await openGarageDoor(event.payload?.doorId);
    }
    });
  5. 跟踪连接状态

    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 },
});
  • 遵循 iOS设置 查看CarPlay场景和特权说明的页面。
  • 遵循 Android设置 Android Auto 类别和清单笔记的页面。

继续 Getting Started

继续 Getting Started 的部分

如果您正在使用 Getting Started 计划原生插件工作时,连接它到 使用 @capgo/capacitor-auto 使用 @capgo/capacitor-auto 的原生能力 Capgo 插件目录 Capgo 插件目录中的产品工作流 Capacitor 插件由 Capgo Capacitor 插件由 Capgo 的实现细节 添加或更新插件 查看添加或更新插件的实现细节 Ionic企业插件替代方案 查看Ionic企业插件替代方案的产品工作流