Démarrage
Copiez un prompt de configuration avec les étapes d'installation et la guide markdown complète pour ce plugin.
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-firebase-messaging`
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/firebase-messaging/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.
Installation
Section intitulée “Installation”Vous pouvez utiliser notre configuration assistée par l'IA pour installer le plugin. Ajoutez les Capgo compétences à votre outil IA en utilisant la commande suivante :
npx skills add https://github.com/Cap-go/capgo-skills --skill capacitor-pluginsEnsuite, utilisez la prompt suivante :
Use the `capacitor-plugins` skill from `Cap-go/capgo-skills` to install the `@capgo/capacitor-firebase-messaging` plugin in my project.Si vous préférez la configuration manuelle, installez le plugin en exécutant les commandes suivantes et suivez les instructions spécifiques à la plateforme ci-dessous :
bun add @capgo/capacitor-firebase-messagingbunx cap syncImporter
Section intitulée “Importer”import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';API Vue d'ensemble
Section intitulée “API Vue d'ensemble”checkPermissions
Section intitulée “checkPermissions”Vérifiez la permission pour recevoir les notifications push.
Activé Android, cette méthode n'a besoin d'être appelée que sur Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
Section intitulée “requestPermissions”Demandez la permission pour recevoir les notifications push.
Activé AndroidSeule cette méthode doit être appelée sur Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();isSupported
Section intitulée “isSupported”Vérifie si tous les API requis existent.
Renvoie toujours true sur Android et iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.isSupported();getToken
Section intitulée “getToken”Inscrivez l'application pour recevoir les notifications push. Renvoie un jeton FCM pouvant être utilisé pour envoyer des messages push à cette instance de Messaging.
Cette méthode réactive également l'auto-init FCM.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();deleteToken
Section intitulée “deleteToken”Supprimez le jeton FCM et désinscrivez l'application pour arrêter de recevoir les notifications push. Peut être appelé, par exemple, lorsqu'un utilisateur se déconnecte.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();getDeliveredNotifications
Section intitulée “getDeliveredNotifications”Obtenez une liste de notifications qui sont visibles sur l'écran des notifications.
Remarque : Cette méthode retournera toutes les notifications livrées, y compris les notifications locales, et non seulement les notifications FCM.
Sur Android, le champ de données de la notification FCM NE sera PAS inclus.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();removeDeliveredNotifications
Section intitulée “removeDeliveredNotifications”Supprimez des notifications spécifiques de l'écran des notifications.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);removeAllDeliveredNotifications
Section intitulée “removeAllDeliveredNotifications”Supprimer toutes les notifications de l'écran des notifications.
Remarque : cela supprimera toutes les notifications livrées, y compris les notifications locales, et non seulement les notifications FCM.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();subscribeToTopic
Section intitulée “s'abonnerAuSujet”S'abonne au sujet en arrière-plan.
Seulement disponible pour Android et iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);unsubscribeFromTopic
Section intitulée “seDésabonnerDuSujet”Se désabonne du sujet en arrière-plan.
Seulement disponible pour Android et iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);createChannel
Section intitulée “créerChaîne”Créer un canal de notification.
Disponible uniquement pour Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);deleteChannel
Section intitulée “supprimer le canal”Supprimer un canal de notification.
Disponible uniquement pour Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);listChannels
Section intitulée “liste des canaux”Lister les canaux de notification disponibles.
Disponible uniquement pour Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();Référence de type
Référence de typePermissionStatus
État de permissionexport interface PermissionStatus { /** * @since 0.2.2 */ receive: PermissionState;}IsSupportedResult
Résultat de la prise en chargeexport interface IsSupportedResult { /** * @since 0.3.1 */ isSupported: boolean;}GetTokenOptions
Options de récupération de jetonexport interface GetTokenOptions { /** * Your VAPID public key, which is required to retrieve the current registration token on the web. * * Only available for Web. */ vapidKey?: string; /** * The service worker registration for receiving push messaging. * If the registration is not provided explicitly, you need to have a `firebase-messaging-sw.js` at your root location. * * Only available for Web. */ serviceWorkerRegistration?: ServiceWorkerRegistration;}GetTokenResult
Résultat de récupération de jetonexport interface GetTokenResult { /** * @since 0.2.2 */ token: string;}GetDeliveredNotificationsResult
Résultat de notifications livréesexport interface GetDeliveredNotificationsResult { /** * @since 0.2.2 */ notifications: Notification[];}RemoveDeliveredNotificationsOptions
Options de suppression de notifications livréesexport interface RemoveDeliveredNotificationsOptions { /** * @since 0.4.0 */ notifications: Notification[];}SubscribeToTopicOptions
Section intitulée « Options d'abonnement à un sujet »export interface SubscribeToTopicOptions { /** * The name of the topic to subscribe. * * @since 0.2.2 */ topic: string;}UnsubscribeFromTopicOptions
Section intitulée « Options d'abonnement à un sujet »export interface UnsubscribeFromTopicOptions { /** * The name of the topic to unsubscribe from. * * @since 0.2.2 */ topic: string;}CreateChannelOptions
Section intitulée « Options de création de canal »export type CreateChannelOptions = Channel;DeleteChannelOptions
Section intitulée « Options de suppression de canal »export interface DeleteChannelOptions { /** * The channel identifier. * * @since 1.4.0 */ id: string;}ListChannelsResult
Section intitulée « Résultats de la liste des canaux »export interface ListChannelsResult { channels: Channel[];}TokenReceivedListener
Section intitulée « Écouteur de réception de jeton »Appel de rappel pour recevoir l'événement de réception du jeton.
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;Source De Vérité
Section intitulée « Source De Vérité »Cette page est générée à partir du plugin’s src/definitions.tsRe-faire la synchronisation lorsque le public API change en amont.
Continuez de Getting Started
Section intitulée « Continuez de Getting Started »Si vous utilisez Getting Started pour planifier la mise en page du tableau de bord et les API opérations, connectez-le avec API Overview pour les détails d'implémentation dans API Vue d'ensemble, Introduction pour les détails d'implémentation dans Introduction, API Clés pour les détails d'implémentation dans API Clés, Appareils pour les détails d'implémentation dans Appareils, et Ensembles pour les détails d'implémentation dans Ensembles.