【问题标题】:firebase.messaging().setBackgroundMessageHandler(*) 'handler' expected a functionfirebase.messaging().setBackgroundMessageHandler(*) 'handler' 期望一个函数
【发布时间】:2021-03-18 00:31:51
【问题描述】:

每当我热重新加载我的应用程序或引发未处理的异常并使我的 React Native 应用程序崩溃时,都会弹出此错误消息。我的 index.js 有

firebase.messaging().setBackgroundMessageHandler(async remoteMessage => {
  console.log(JSON.stringify(remoteMessage));
});

【问题讨论】:

    标签: reactjs firebase react-native firebase-cloud-messaging


    【解决方案1】:

    这可能有几个原因。 JSON.stringify(remoteMessage) 可能会崩溃,并且由于您没有在承诺链中添加 catch ,因此您会收到未处理的异常。 您能否将代码修改为以下内容:

    firebase.messaging().setBackgroundMessageHandler(async remoteMessage => {
      console.log(JSON.stringify(remoteMessage));
    }).catch(e => {console.log(e)});
    

    然后分析崩溃堆栈

    【讨论】:

    • 在此处添加 .catch 会引发类型错误
    • 你导入了firebase/messaging吗?比如导入“firebase/messaging”
    • 是的,该应用程序运行良好并发送通知,但任何时候我强制保存都会发生此错误
    猜你喜欢
    • 2018-10-18
    • 2017-04-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    • 1970-01-01
    • 1970-01-01
    • 2020-04-14
    相关资源
    最近更新 更多