Skip to content

Instantly share code, notes, and snippets.

@thanujaa-vb
thanujaa-vb / config.js
Last active May 24, 2023 05:41
Firebase Notifications
{
"expo": {
"android": {
"googleServicesFile": "./google-services.json"
},
"ios": {
"googleServicesFile": "./GoogleService-Info.plist"
},
"plugins": [
"@react-native-firebase/app",
{
"expo": {
"android": {
"googleServicesFile": "./google-services.json"
},
"ios": {
"googleServicesFile": "./GoogleService-Info.plist"
},
"plugins": [
"@react-native-firebase/app",
const message = {
notification: {
title: 'New Notification',
body: 'This is a new notification',
},
token: 'DEVICE_TOKEN',
};
admin.messaging().send(message).then((response) => {
console.log('Successfully sent message: ', response);
const admin = require('firebase-admin');
const serviceAccount = require('path/to/serviceAccountkey.json');
admin.initializeApp({
credential: admin.credential.cert(serviceAccount),
});
npm install --save firebase-admin
import messaging from '@react-native-firebase/messagig';
// Handle incoming notifications when app is in foreground
messaging().onMessage(async (remoteMessage) => {
console.log('Received foreground notification: ', remoteMessage);
});
// Handle incoming notifications when app is in background
messaging().onNotificationOpenedApp(async (remoteMessage) => {
console.log('Received background notification: ', remoteMessage);
import messaging from '@react-native-firebase/messagig';
messaging().getToken().then((token) => {
console.log(token);
});
npm install @react-native-firebase/app @react-native-firebase/messaging