Démarrage
Copiez une invite de configuration avec les étapes d'installation et le guide markdown complet 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.
Installez
Section intitulée « Installez »bun add @capgo/capacitor-firebase-messagingbunx cap syncImporter
Section intitulée « Importer »import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';API Aperçu
Section intitulée « API Aperçu »checkPermissions
Section intitulée « checkPermissions »Vérifiez les permissions pour recevoir des notifications push.
Sur AndroidSeulement appelez cette méthode sur Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
Section intitulée “requestPermissions”Demander la permission de recevoir les notifications push.
Sur AndroidSeulement appelez cette méthode sur Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();isSupported
Section intitulée “isSupported”Vérifiez si tous les API requis existent.
Toujours retourne 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 à cet 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ée, 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 renvoie 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”Supprimer 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 “subscribeToTopic”S'abonner à un 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 “se désinscrire de la rubrique”Se désinscrit de la rubrique en arrière-plan.
Disponible uniquement pour Android et iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);createChannel
Section intitulée “créer une rubrique”Crée une rubrique de notification.
Only available for Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);deleteChannel
Section intitulée “supprimer une rubrique”Supprime une rubrique de notification.
Only available for Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);listChannels
Section intitulée “listChannels”Lister les canaux de notification disponibles.
Seulement disponible pour Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();Référence de type
Section intitulée “Type Reference”PermissionStatus
Section intitulée “PermissionStatus”export interface PermissionStatus { /** * @since 0.2.2 */ receive: PermissionState;}IsSupportedResult
Section intitulée “IsSupportedResult”export interface IsSupportedResult { /** * @since 0.3.1 */ isSupported: boolean;}GetTokenOptions
Section intitulée “GetTokenOptions”export 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
Section intitulée « Résultat de GetToken »export interface GetTokenResult { /** * @since 0.2.2 */ token: string;}GetDeliveredNotificationsResult
Section intitulée « Résultat de GetDeliveredNotifications »export interface GetDeliveredNotificationsResult { /** * @since 0.2.2 */ notifications: Notification[];}RemoveDeliveredNotificationsOptions
Section intitulée « Options de suppression de notifications livrées »export 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 « Supprimer les options de canal »export interface DeleteChannelOptions { /** * The channel identifier. * * @since 1.4.0 */ id: string;}ListChannelsResult
Section intitulée « Liste des résultats de canal »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 src/definitions.tsRe-générez la synchronisation lorsque les modifications publiques API sont mises à jour en amont.
Continuez de l'Accueil
Section intitulée « Continuez de l'Accueil »Si vous utilisez Accueil pour planifier le tableau de bord et les opérations API , connectez-le à Vue d'ensemble de API pour les détails d'implémentation dans Vue d'ensemble de API Introduction pour les détails d'implémentation dans Introduction, Clés de API pour les détails d'implémentation dans Clés de API Appareils pour les détails d'implémentation dans les appareils, et Bundles pour les détails d'implémentation dans les Bundles.