Getting Started
Dieser Inhalt ist in Ihrer Sprache noch nicht verfügbar.
Install
Section titled “Install”bun add @capgo/capacitor-firebase-messagingbunx cap syncImport
Section titled “Import”import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';API Overview
Section titled “API Overview”checkPermissions
Section titled “checkPermissions”Check permission to receive push notifications.
On Android, this method only needs to be called on Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.checkPermissions();requestPermissions
Section titled “requestPermissions”Request permission to receive push notifications.
On Android, this method only needs to be called on Android 13+.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.requestPermissions();isSupported
Section titled “isSupported”Checks if all required APIs exist.
Always returns true on Android and iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.isSupported();getToken
Section titled “getToken”Register the app to receive push notifications. Returns a FCM token that can be used to send push messages to that Messaging instance.
This method also re-enables FCM auto-init.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getToken();deleteToken
Section titled “deleteToken”Delete the FCM token and unregister the app to stop receiving push notifications. Can be called, for example, when a user signs out.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteToken();getDeliveredNotifications
Section titled “getDeliveredNotifications”Get a list of notifications that are visible on the notifications screen.
Note: This will return all delivered notifications, including local notifications, and not just FCM notifications.
On Android, the data field of the FCM notification will NOT be included.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.getDeliveredNotifications();removeDeliveredNotifications
Section titled “removeDeliveredNotifications”Remove specific notifications from the notifications screen.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeDeliveredNotifications({} as RemoveDeliveredNotificationsOptions);removeAllDeliveredNotifications
Section titled “removeAllDeliveredNotifications”Remove all notifications from the notifications screen.
Note: This will remove all delivered notifications, including local notifications, and not just FCM notifications.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.removeAllDeliveredNotifications();subscribeToTopic
Section titled “subscribeToTopic”Subscribes to topic in the background.
Only available for Android and iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.subscribeToTopic({} as SubscribeToTopicOptions);unsubscribeFromTopic
Section titled “unsubscribeFromTopic”Unsubscribes from topic in the background.
Only available for Android and iOS.
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.unsubscribeFromTopic({} as UnsubscribeFromTopicOptions);createChannel
Section titled “createChannel”Create a notification channel.
Only available for Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.createChannel({} as CreateChannelOptions);deleteChannel
Section titled “deleteChannel”Delete a notification channel.
Only available for Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.deleteChannel({} as DeleteChannelOptions);listChannels
Section titled “listChannels”List the available notification channels.
Only available for Android (SDK 26+).
import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';
await FirebaseMessaging.listChannels();Type Reference
Section titled “Type Reference”PermissionStatus
Section titled “PermissionStatus”export interface PermissionStatus { /** * @since 0.2.2 */ receive: PermissionState;}IsSupportedResult
Section titled “IsSupportedResult”export interface IsSupportedResult { /** * @since 0.3.1 */ isSupported: boolean;}GetTokenOptions
Section titled “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 titled “GetTokenResult”export interface GetTokenResult { /** * @since 0.2.2 */ token: string;}GetDeliveredNotificationsResult
Section titled “GetDeliveredNotificationsResult”export interface GetDeliveredNotificationsResult { /** * @since 0.2.2 */ notifications: Notification[];}RemoveDeliveredNotificationsOptions
Section titled “RemoveDeliveredNotificationsOptions”export interface RemoveDeliveredNotificationsOptions { /** * @since 0.4.0 */ notifications: Notification[];}SubscribeToTopicOptions
Section titled “SubscribeToTopicOptions”export interface SubscribeToTopicOptions { /** * The name of the topic to subscribe. * * @since 0.2.2 */ topic: string;}UnsubscribeFromTopicOptions
Section titled “UnsubscribeFromTopicOptions”export interface UnsubscribeFromTopicOptions { /** * The name of the topic to unsubscribe from. * * @since 0.2.2 */ topic: string;}CreateChannelOptions
Section titled “CreateChannelOptions”export type CreateChannelOptions = Channel;DeleteChannelOptions
Section titled “DeleteChannelOptions”export interface DeleteChannelOptions { /** * The channel identifier. * * @since 1.4.0 */ id: string;}ListChannelsResult
Section titled “ListChannelsResult”export interface ListChannelsResult { channels: Channel[];}TokenReceivedListener
Section titled “TokenReceivedListener”Callback to receive the token received event.
export type TokenReceivedListener = (event: TokenReceivedEvent) => void;Source Of Truth
Section titled “Source Of Truth”This page is generated from the plugin’s src/definitions.ts. Re-run the sync when the public API changes upstream.