【问题标题】:React Native PushNotification onNotification methodReact Native PushNotification onNotification 方法
【发布时间】:2017-06-02 10:50:26
【问题描述】:

我正在收到来自服务器的通知。收到通知后,当我点击它时,同样的通知又来了。更多我点击它更多的通知来了。

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

我正在使用以下链接 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,
    });

【问题讨论】:

  • 我认为您应该检查通知是远程通知还是本地通知。通常情况下,如果是远程通知,则发送本地通知,如果是本地通知,则与用户进行交互。
  • 在 Navneet 建议的答案的帮助下解决了我的问题

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


【解决方案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,
    });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-11-24
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多