firebase - 尝试使用 react native 0.63 设置 firebase 时出错
问题描述
我是对原生和 firebase 做出反应的新手,我正在尝试创建一个使用 firebase 在 iOS 中发送后台通知的应用程序。
当我运行我的应用程序时,我似乎收到以下错误消息并且我的应用程序将无法运行。
TypeError: (0, _app2.messaging) 不是函数。(在 '(0, _app2.messaging)()' 中,'(0, _app2.messaging)' 未定义)
这是我的firebase代码。
import {name as appName} from './app.json';
import {AppRegistry} from 'react-native';
import {messaging} from '@react-native-firebase/app';
requestUserPermission = async () => {
const authStatus = await messaging().requestPermission();
const enabled =
authStatus === messaging.AuthorizationStatus.AUTHORIZED ||
authStatus === messaging.AuthorizationStatus.PROVISIONAL;
if (enabled) {
console.log('Authorization status:', authStatus);
}
};
// Register background handler
messaging().setBackgroundMessageHandler(async (remoteMessage) => {
console.log('Messaage handled in the background!', remoteMessage);
});
HeadlessCheck = ({ isHeadless }) => {
if (isHeadless) {
// App has beeen launched in the background by iOS, ignore
return null;
}
return <App />;
}
AppRegistry.registerComponent(appName, () => HeadlessCheck);
我可能写错了我的firebase代码,因为我是firebase的新手,我仍然不确定我在做什么,只是想遵循一些在线教程。
我确实谷歌了这个问题,但似乎没有人遇到它。我试图删除我的 node_modules 文件夹并再次运行 yarn,但这并没有解决问题。
解决方案
似乎消息不存在,我注意到您正在从@react-native-firebase/app
. 按照文档(https://rnfirebase.io/messaging/usage)看起来你需要一个不同的模块。
安装消息模块:
# Install the messaging module
yarn add @react-native-firebase/messaging
# If you're developing your app using iOS, run this command
cd ios/ && pod install
导入messaging
使用
import messaging from '@react-native-firebase/messaging';
推荐阅读
- javascript - JS 数学方法的问题:函数正在删除多个最小值/最大值(我认为?)
- .net - 没有为 msversion 找到 cmake vs 编译器:4 (windows7)
- java - 如何使用 Spring 显示本地图像(保存在 C 盘上)?
- r - 删除分组条形图的 x 轴上因子(年)之间的空间
- amazon-web-services - 使用 AWS Beanstalk Hooks 执行 HTTP GET 请求
- php - 如何使用php“sprintf”在列类型“text”上使用“LIKE”过滤mysql
- java - 如何为 RecyclerView 中的项目制作粘性按钮?
- flutter - 颤振:小部件的边缘与第二个小部件重叠
- java - Team City 构建失败:-source 1.6 不支持钻石运算符
- python - 类中的包罗万象的方法,将所有未知函数传递给类中的实例