Saltare al contenuto

Inizia a utilizzare

Fenestra del terminale
bun add @capgo/capacitor-firebase-messaging
bunx cap sync
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

Verifica la possibilitĂ  di ricevere notifiche push.

Attivo Android, questo metodo deve essere chiamato solo su Android 13+.

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

Richiedi il permesso per ricevere notifiche push.

Su Android, questo metodo deve essere chiamato solo su Android 13+.

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

Verifica se esistono tutte le API richieste.

Sempre restituisce true su Android e iOS.

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

Registra l'app per ricevere notifiche push. Restituisce un token FCM che può essere utilizzato per inviare messaggi push a quel Messaging instance.

Questo metodo riabilita anche l'inizializzazione FCM automatica.

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

Elimina il token FCM e disiscrivi l'app per fermare le notifiche push. Può essere chiamato, ad esempio, quando un utente si disconnette.

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

Ottenere una lista di notifiche che sono visibili sulla schermata delle notifiche.

Nota: Questo restituirĂ  tutte le notifiche consegnate, comprese le notifiche locali, e non solo le notifiche FCM.

Su Android, il campo dati della notifica FCM NON sarĂ  incluso.

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

Elimina specifiche notifiche dalla schermata delle notifiche.

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

Elimina tutte le notifiche dalla schermata delle notifiche.

Nota: Questo eliminerĂ  tutte le notifiche consegnate, comprese le notifiche locali, e non solo le notifiche FCM.

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

Si sottoscrive al tema in background.

Disponibile solo per Android e iOS.

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

Si disiscrive dal tema in background.

Disponibile solo per Android e iOS.

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

Crea un canale di notifica.

Disponibile solo per Android (SDK 26+).

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

Elimina un canale di notifica.

Disponibile solo per Android (SDK 26+).

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

Elenco dei canali di notifica disponibili.

Disponibile solo per 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[];
}

Callback per ricevere l'evento del token ricevuto.

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

Questa pagina è generata dal plugin e può essere aggiornata. src/definitions.tsRiepilogare la sincronizzazione quando le informazioni pubbliche API cambiano nell'area upstream.

Se stai utilizzando Getting Started per pianificare dashboard e API operazioni, connettilo con API Panoramica per i dettagli di implementazione in API Panoramica, Introduzione per i dettagli di implementazione in Introduzione, API Chiavi per i dettagli di implementazione in API Chiavi, Dispositivi per i dettagli di implementazione in Dispositivi, e Bundle per i dettagli di implementazione in Bundle.