React Native PushNotification onNotification方法

时间:2017-06-02 10:50:26

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

我正在从服务器获取通知。收到通知后,当我点击它时,再次发出相同的通知。更多我点击它的通知即将到来。

我的问题是我是否遵循上述代码中的正确方法?如果没有,那么请建议我正确的。如何处理通知点击?所以,我可以在点击时显示特定的视图。

我正在使用以下链接 https://github.com/zo0r/react-native-push-notification

提前致谢:)

PushNotification.configure({

      onNotification: function (notification) {
        console.log('NOTIFICATION:', notification)
         PushNotification.localNotification({
          largeIcon: "ic_launcher",
          title: notification.title, 
          message: notification.message, 
        });

      },
      senderID: "my sender ID",
      popInitialNotification: true,
      requestPermissions: true,
    });

1 个答案:

答案 0 :(得分:1)

我尝试过以下方法来解决这个问题

PushNotification.configure({

      onNotification: function (notification) {
        console.log('NOTIFICATION:', notification)
        const clicked = notification.userInteraction;
        if (clicked) {
         ToastAndroid.show(notification.message,ToastAndroid.CENTER);
        } else {
          PushNotification.localNotification({
            largeIcon: "ic_launcher",
            title: "Test",
            //message: JSON.stringify(xyz.notificationResponse.bookingId), 
          });
        }
        ToastAndroid.show(notification.message,ToastAndroid.CENTER);
      },


      senderID: "your sender id",
      popInitialNotification: true,
      requestPermissions: true,
    });