快速入门
复制包含安装步骤和该插件完整 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-rich-notifications`
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/rich-notifications/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 工具中:
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-notificationsbunx 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;示例:createChannel
标题为“示例:createChannel”的章节import { RichNotifications } from '@capgo/capacitor-rich-notifications';
await RichNotifications.createChannel({ id: 'alerts', name: 'Alerts', importance: 'high',});示例:display
标题为“示例:display”的章节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);});