Guide
Utiliser Rich Notifications dans Capacitor
Utiliser @capgo/capacitor-rich-notifications
Notifications locales avec canaux Android, layouts de progression, boutons d’action, planification et niveaux d’interruption iOS.
Installer
bun add @capgo/capacitor-rich-notifications
bunx cap sync
Ce que ce plugin expose
checkPermission- Vérifier l'état de l'autorisation des notifications locales.requestPermission- Demander l'autorisation des notifications locales.createChannel- Créer un canal de notification Android.createChannelGroup- Créer un groupe de canaux Android.deleteChannel- Supprimer un canal de notification Android.display- Afficher une notification locale immédiatement.schedule- Planifier une notification locale pour plus tard.cancel- Annuler une notification par son id.cancelAll- Annuler toutes les notifications gérées par ce plugin.getDisplayed- Liste des notifications affichées dans le shade ou au centre.getPending- Lister les notifications planifiées non encore affichées.getInitialNotification- Renvoyer la notification qui a ouvert l’application, le cas échéant.setBadge- Set the app icon badge count on iOS.registerActions- Enregistrer une catégorie d’actions réutilisable.getPluginVersion- Renvoie le marqueur de version de l'implémentation de la plateforme.addListener- Écouter les événements d’appui et de fermeture.
Exemple d'utilisation
requestPermission et 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 },
});
Référence complète
- GitHub : https://github.com/Cap-go/capacitor-rich-notifications/
- Docs : /docs/plugins/rich-notifications/