You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用React Native Firebase Cloud Messaging时遭遇弃用警告的问题咨询

使用React Native Firebase Cloud Messaging时遭遇弃用警告的问题咨询

我最近新建了一个React Native项目,正在使用React Native Firebase的Cloud Messaging功能,完全是照着官方文档里的示例代码来写的,但在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.

警告截图:
弃用警告截图

以下是我目前的代码:
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
    */
});

想请教一下,现在正确的用法应该是什么?为什么官方文档还在展示旧版本的使用示例呢?

备注:内容来源于stack exchange,提问作者Hasan ABLAK

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.04.13 18:29:35