Skip to main content
@capgo/capacitor-firebase-messaging Communication Open source

Firebase Messaging Capacitor plugin

Capacitor plugin for Firebase Cloud Messaging (FCM)

Install

bun add @capgo/capacitor-firebase-messaging bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-firebase-messaging
  • pnpm add @capgo/capacitor-firebase-messaging
  • yarn add @capgo/capacitor-firebase-messaging

Guide

How to use Firebase Messaging in Capacitor

Using @capgo/capacitor-firebase-messaging

Capacitor plugin for Firebase Cloud Messaging (FCM).

Install

bun add @capgo/capacitor-firebase-messaging
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

API at a glance

Method Description
checkPermissions Check permission to receive push notifications.
requestPermissions Request permission to receive push notifications.
isSupported Checks if all required APIs exist.
getToken Register the app to receive push notifications. Returns a FCM token that can be used to send push messages to that Messaging instance.
deleteToken Delete the FCM token and unregister the app to stop receiving push notifications. Can be called, for example, when a user signs out.
getDeliveredNotifications Get a list of notifications that are visible on the notifications screen.
removeDeliveredNotifications Remove specific notifications from the notifications screen.
removeAllDeliveredNotifications Remove all notifications from the notifications screen.
subscribeToTopic Subscribes to topic in the background.
unsubscribeFromTopic Unsubscribes from topic in the background.
createChannel Create a notification channel.
deleteChannel Delete a notification channel.
listChannels List the available notification channels.

Examples

checkPermissions()

Check permission to receive push notifications.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

const result = await FirebaseMessaging.checkPermissions();
console.log(result);

requestPermissions()

Request permission to receive push notifications.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

const result = await FirebaseMessaging.requestPermissions();
console.log(result);

isSupported()

Checks if all required APIs exist.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

const result = await FirebaseMessaging.isSupported();
console.log(result);

getToken()

Register the app to receive push notifications. Returns a FCM token that can be used to send push messages to that Messaging instance.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

const result = await FirebaseMessaging.getToken();
// The result holds sensitive values: use it without logging it.

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

Get a list of notifications that are visible on the notifications screen.

import { FirebaseMessaging } from '@capgo/capacitor-firebase-messaging';

const result = await FirebaseMessaging.getDeliveredNotifications();
console.log(result);

The table above lists the 13 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.

Listen to events

addListener returns a handle. Call handle.remove() when the screen unmounts, or FirebaseMessaging.removeAllListeners() to clear every listener.

Full reference

Keep going from Using @capgo/capacitor-firebase-messaging

If you are using Using @capgo/capacitor-firebase-messaging to plan native plugin work, connect it with Capgo Plugin Directory for the product workflow in Capgo Plugin Directory, Capacitor Plugins by Capgo for the implementation detail in Capacitor Plugins by Capgo, Adding or Updating Plugins for the implementation detail in Adding or Updating Plugins, Ionic Enterprise Plugin Alternatives for the product workflow in Ionic Enterprise Plugin Alternatives, and Capgo Native Builds for the product workflow in Capgo Native Builds.

FAQ

Firebase Messaging plugin FAQ

How do I install the Firebase Messaging plugin in a Capacitor app?

Run "bun add @capgo/capacitor-firebase-messaging" (or "npm install @capgo/capacitor-firebase-messaging"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-firebase-messaging" in your app code.

Does @capgo/capacitor-firebase-messaging work with React, Vue and Angular?

Yes. Firebase Messaging is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-firebase-messaging support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-firebase-messaging free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-firebase/tree/main/packages/messaging and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses Firebase Messaging without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship Firebase Messaging changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo