【问题标题】:Error handling on react-native-fcmreact-native-fcm 上的错误处理
【发布时间】:2017-03-08 20:10:44
【问题描述】:

我正在使用 https://github.com/evollu/react-native-fcm 在我的 react-native 应用程序中集成 FCM。 通知有效,但我每次都收到此错误。

console.error: "Notification handler err", {"line":67974,"column":14,"sourceURL":"http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false"}

环境: react-native-cli: 2.0.1

反应原生:0.40.0

react-native-fcm: 6.1.0

我正在 Android 版本 6.0.1 上进行测试,并且该应用正在前台运行。

【问题讨论】:

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


    【解决方案1】:

    我删除了 index.js 上的旧代码 Firebase 初始化代码,它导致了错误。

    firebase.initializeApp({
        apiKey: "",
        authDomain: "",
        databaseURL: "",
        storageBucket: ""
    });
    

    我删除了它,它现在可以工作了。

    【讨论】:

      【解决方案2】:

      对于 react-native fcm。查看对象 aps.alert

      FCM.on("FCMNotificationReceived", (notification) => {
            if (Platform.OS === 'ios') {
              if (notification && notification.aps) {
                const localNotification = {
                  title: notification.aps.alert.title,
                  body: notification.aps.alert.body,
                  show_in_foreground: true,
                }
                FCM.presentLocalNotification(localNotification);
              }
            }
          });
      
      
      FCM.on("FCMNotificationReceived", (notification) => {
      // Also trigged when FCM.presentLocalNotification() and callback a notification without **aps** object;
      // So the app crash, error
      // Just check if (notification && notification.aps) and make localNotification object like above code
      }) 
      

      【讨论】:

        猜你喜欢
        • 2018-07-09
        • 1970-01-01
        • 2020-06-05
        • 1970-01-01
        • 2016-06-12
        • 1970-01-01
        • 2018-11-24
        • 2020-10-23
        • 1970-01-01
        相关资源
        最近更新 更多