Aller directement au contenu

Démarrage

Fenêtre de terminal
bun add @capgo/capacitor-firebase-messaging
bunx cap sync
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

Vérifiez les permissions pour recevoir les notifications push.

Sur 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();

Demandez les permissions pour recevoir les notifications push.

Sur Android, cette méthode n'a besoin d'être appelée que sur Android 13+.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();

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();

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();

Supprime le jeton FCM et désinscrit 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();

Obtenez une liste de notifications 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();

Supprimer des notifications spécifiques de l’écran des notifications.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);

Supprimer toutes les notifications de l’écran des notifications.

Remarque : Cette méthode 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();

Souscrit au sujet en arrière-plan.

Disponible uniquement pour Android et iOS.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);

Se désinscrit du sujet en arrière-plan.

Disponible uniquement pour Android et iOS.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);

Crée une chaîne de notification.

Disponible uniquement pour Android (seulement à partir de SDK 26+).

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);

Supprimer un canal de notification.

Disponible uniquement pour Android (SDK 26+).

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);

Lister les canaux de notification disponibles.

Disponible uniquement pour Android (SDK 26+).

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();
export interface PermissionStatus {
/**
* @since 0.2.2
*/
receive: PermissionState;
}
export interface IsSupportedResult {
/**
* @since 0.3.1
*/
isSupported: boolean;
}
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;
}
export interface GetTokenResult {
/**
* @since 0.2.2
*/
token: string;
}
export interface GetDeliveredNotificationsResult {
/**
* @since 0.2.2
*/
notifications: Notification[];
}
export interface RemoveDeliveredNotificationsOptions {
/**
* @since 0.4.0
*/
notifications: Notification[];
}
export interface SubscribeToTopicOptions {
/**
* The name of the topic to subscribe.
*
* @since 0.2.2
*/
topic: string;
}
export interface UnsubscribeFromTopicOptions {
/**
* The name of the topic to unsubscribe from.
*
* @since 0.2.2
*/
topic: string;
}
export type CreateChannelOptions = Channel;
export interface DeleteChannelOptions {
/**
* The channel identifier.
*
* @since 1.4.0
*/
id: string;
}
export interface ListChannelsResult {
channels: Channel[];
}

Appel de rappel pour recevoir l'événement de réception du jeton.

export type TokenReceivedListener = (event: TokenReceivedEvent) => void;

Cette page est générée à partir du plugin’s src/definitions.tsRe-faites la synchronisation lorsque le public API change en amont.