Passer 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érifier la permission pour recevoir des notifications push.

Activé AndroidCette méthode n'a besoin d'être appelée que sur Android 13 et ultérieurs.

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

Demander la permission pour recevoir des 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 à cet instance de Messaging.

Cette méthode réactive également l'auto-init FCM.

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

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

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

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

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

Supprime toutes les notifications de l'écran de notifications.

Remarque : Cette action 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();

S'abonne 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ésabonne 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éer un canal de notification.

Seulement disponible pour Android (SDK 26+).

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

Supprimer un canal de notification.

Seulement disponible pour Android (SDK 26+).

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

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

Référence de type
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-faire la synchronisation lorsque le public API change en amont.

Si vous utilisez Getting Started pour planifier le tableau de bord et les API opérations, connectez-le avec API Présentation pour les détails d'implémentation dans API Présentation, 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.