Anleitung
Rich Notifications in Capacitor nutzen
Verwendung von @capgo/capacitor-rich-notifications
Lokale Notifications mit Android Channels, Progress Layouts, Action Buttons, Scheduling und iOS Interruption Levels.
Installieren
bun add @capgo/capacitor-rich-notifications
bunx cap sync
Was dieses Plugin bietet
checkPermission- Status der lokalen Benachrichtigungsberechtigung prüfen.requestPermission- Lokale Benachrichtigungsberechtigung anfordern.createChannel- Android Notification Channel erstellen.createChannelGroup- Android Channel Group erstellen.deleteChannel- Android Notification Channel löschen.display- Lokale Benachrichtigung sofort anzeigen.schedule- Lokale Benachrichtigung planen.cancel- Eine Benachrichtigung per ID abbrechen.cancelAll- Alle vom Plugin verwalteten Benachrichtigungen abbrechen.getDisplayed- Liste der Benachrichtigungen im Shade oder im Zentrum.getPending- List scheduled notifications not yet shown.getInitialNotification- Die Benachrichtigung zurückgeben, die die App geöffnet hat (falls vorhanden).setBadge- App-Icon-Badge auf iOS festlegen.registerActions- Eine wiederverwendbare Action-Kategorie registrieren.getPluginVersion- Gibt den Versionsmarker der Plattform-Implementierung zurück.addListener- Auf Press- und Dismiss-Events hören.
Anwendungsbeispiel
requestPermission und 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 },
});
Vollständige Referenz
- GitHub: https://github.com/Cap-go/capacitor-rich-notifications/
- Docs: /docs/plugins/rich-notifications/