最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Getting deprecation warning using FirebaseCloud Messaging in react native - Stack Overflow

programmeradmin0浏览0评论

I created a new React Native project and I'm using rnfirebase.io Cloud Messaging. The documentation says to use it like in this example and that's how I'm using it: Doc

But I have warning message in Chrome DevTools

index.js:38 This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: Please use getApp() instead.

Bellow my code here; index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';

AppRegistry.registerComponent(appName, () => App);

messaging()
.onMessage(async notification => {
    /*
        Code goes here
    */
});

messaging()
.setBackgroundMessageHandler(async remoteMessage => {
    /*
        Code goes here
    */
});

What is the correct use? Why this document showing old version usage example

I created a new React Native project and I'm using rnfirebase.io Cloud Messaging. The documentation says to use it like in this example and that's how I'm using it: Doc

But I have warning message in Chrome DevTools

index.js:38 This method is deprecated (as well as all React Native Firebase namespaced API) and will be removed in the next major release as part of move to match Firebase Web modular SDK API. Please see migration guide for more details: https://rnfirebase.io/migrating-to-v22 Please use getApp() instead.

Bellow my code here; index.js

import {AppRegistry} from 'react-native';
import App from './App';
import {name as appName} from './app.json';
import messaging from '@react-native-firebase/messaging';

AppRegistry.registerComponent(appName, () => App);

messaging()
.onMessage(async notification => {
    /*
        Code goes here
    */
});

messaging()
.setBackgroundMessageHandler(async remoteMessage => {
    /*
        Code goes here
    */
});

What is the correct use? Why this document showing old version usage example

Share Improve this question edited Mar 12 at 21:39 Hasan ABLAK asked Mar 12 at 9:06 Hasan ABLAKHasan ABLAK 1011 silver badge7 bronze badges 2
  • On Stack Overflow, please don't show pictures of text and code. Copy the text into the question itself and format it so that it's easy to read, copy, and search. You can edit the question to correct this using the edit link at the bottom. – Doug Stevenson Commented Mar 12 at 12:44
  • ok sir i added. – Hasan ABLAK Commented Mar 12 at 21:39
Add a comment  | 

1 Answer 1

Reset to default 1

It seems your code is using the namespaced API, but the latest React Native firebase docs requires you to migrate to the modular API.

update your index.js file to use the new getApp() method instead of calling messaging() directly.

import { AppRegistry } from 'react-native';
import App from './App';
import { name as appName } from './app.json';
import { getApp } from 'firebase/app';
import { getMessaging, onMessage } from '@react-native-firebase/messaging';


const firebaseApp = getApp();
const messaging = getMessaging(firebaseApp);

onMessage(messaging, async (notification) => {
    console.log('Received foreground notification:', notification);
});

messaging.setBackgroundMessageHandler(async (remoteMessage) => {
    console.log('Received background notification:', remoteMessage);
});

AppRegistry.registerComponent(appName, () => App);

发布评论

评论列表(0)

  1. 暂无评论