ガイド
Capacitor で Rich Notifications を使う方法
@capgo/capacitor-rich-notifications の使い方
Android のチャネル、プログレスレイアウト、アクションボタン、スケジューリング、iOS の interruption level を備えたローカル通知。
インストール
bun add @capgo/capacitor-rich-notifications
bunx cap sync
このプラグインで利用可能な機能
checkPermission- ローカル通知の権限ステータスを確認します。requestPermission- ローカル通知の権限をリクエストします。createChannel- Androidの通知チャンネルを作成します。createChannelGroup- Androidのチャンネルグループを作成します。deleteChannel- Androidの通知チャンネルを削除します。display- ローカル通知を即座に表示します。schedule- ローカル通知を後で表示するようスケジュールします。cancel- IDを指定して通知を1件キャンセルします。cancelAll- このプラグインで管理されているすべての通知をキャンセルします。getDisplayed- 通知シェードや通知センターに表示されている通知を一覧表示します。getPending- まだ表示されていないスケジュール済み通知を一覧表示します。getInitialNotification- アプリの起動元となった通知があれば、その通知を返します。setBadge- iOSでアプリアイコンのバッジ数を設定します。registerActions- 再利用可能なアクションカテゴリを登録します。getPluginVersion- プラットフォーム実装のバージョンマーカーを返します。addListener- press と dismiss のイベントを監視します。
使用例
requestPermission と display
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',
});
schedule
import { RichNotifications } from '@capgo/capacitor-rich-notifications';
await RichNotifications.schedule({
notification: {
id: 'reminder-1',
title: 'Reminder',
body: 'Your appointment starts soon',
channelId: 'messages',
},
trigger: { type: 'timestamp', timestamp: Date.now() + 60_000 },
});
リファレンス全文
- GitHub: https://github.com/Cap-go/capacitor-rich-notifications/
- ドキュメント: /docs/plugins/rich-notifications/