Socket
Socket
Sign inDemoInstall

@react-native-firebase/messaging

Package Overview
Dependencies
Maintainers
4
Versions
235
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@react-native-firebase/messaging

React Native Firebase - React Native Firebase provides native integration of Firebase Cloud Messaging (FCM) for both Android & iOS. FCM is a cost free service, allowing for server-device and device-device communication. The React Native Firebase Messaging


Version published
Weekly downloads
321K
increased by2.63%
Maintainers
4
Weekly downloads
 
Created

What is @react-native-firebase/messaging?

@react-native-firebase/messaging is a React Native module that provides Firebase Cloud Messaging (FCM) integration for sending and receiving push notifications. It allows developers to handle background and foreground notifications, manage device tokens, and customize notification behavior.

What are @react-native-firebase/messaging's main functionalities?

Receiving Messages

This feature allows the app to receive messages when it is in the foreground. The `onMessage` listener is triggered whenever a new FCM message arrives.

import messaging from '@react-native-firebase/messaging';

messaging().onMessage(async remoteMessage => {
  console.log('A new FCM message arrived!', JSON.stringify(remoteMessage));
});

Requesting Permission

This feature requests the user's permission to receive push notifications. It checks the authorization status and logs it.

import messaging from '@react-native-firebase/messaging';

async function requestUserPermission() {
  const authStatus = await messaging().requestPermission();
  const enabled = authStatus === messaging.AuthorizationStatus.AUTHORIZED || authStatus === messaging.AuthorizationStatus.PROVISIONAL;

  if (enabled) {
    console.log('Authorization status:', authStatus);
  }
}

Getting the FCM Token

This feature retrieves the FCM token for the device, which is necessary for sending targeted notifications to that device.

import messaging from '@react-native-firebase/messaging';

async function getToken() {
  const token = await messaging().getToken();
  console.log('FCM Token:', token);
}

Handling Background Messages

This feature allows the app to handle messages when it is in the background. The `setBackgroundMessageHandler` is triggered for background messages.

import messaging from '@react-native-firebase/messaging';

messaging().setBackgroundMessageHandler(async remoteMessage => {
  console.log('Message handled in the background!', remoteMessage);
});

Other packages similar to @react-native-firebase/messaging

Keywords

FAQs

Package last updated on 04 Jun 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc