跳转到正文

快速入门

GitHub

你可以使用我们的 AI 辅助设置来安装插件。使用以下命令将 Capgo skills 添加到你的 AI 工具中:

终端窗口
bunx 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-rich-notifications` plugin in my project.

如果你更想手动设置,请运行以下命令安装插件,并按照下方各平台的说明操作:

终端窗口
bun add @capgo/capacitor-rich-notifications
bunx cap sync
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
const { status } = await RichNotifications.requestPermission();
if (status !== 'granted') return;
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
await RichNotifications.createChannel({
id: 'alerts',
name: 'Alerts',
importance: 'high',
});
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
const { id } = await RichNotifications.display({
title: 'Hello',
body: 'Tap to open',
channelId: 'alerts',
});
  • 监听器: 在页面卸载时移除句柄。
  • 原生同步:运行 bunx cap sync 在插件升级后。
  • 唯一可信来源:信任 src/definitions.ts 在 GitHub 仓库中。
  • iOS 配置 用于分类和中断级别。
  • Android 配置 来实现 POST_NOTIFICATIONS、通道,以及可选的精确闹钟或前台服务权限。
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
await RichNotifications.requestPermission();
await RichNotifications.createChannel({
id: 'messages',
name: 'Messages',
importance: 'high',
});
await RichNotifications.display({
title: 'Hello',
body: 'Tap to open the app',
channelId: 'messages',
});
await RichNotifications.addListener('press', (event) => {
console.log(event.id, event.actionId, event.input);
});