android - React Native PushNotification onNotification 方法

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

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

我的问题是我在上面的代码中是否遵循了正确的方法?如果没有,请建议我正确的。如何处理通知的点击?因此,我可以在其点击时显示特定 View 。

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

最佳答案

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

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,
    });

关于android - React Native PushNotification onNotification 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44327125/

相关文章:

typescript - 实现 tabmenu 后 Angularfire 身份验证注销方法不起作用

java - 当jni库再次加载时会发生什么?

ios - 如何像 uipickerview 中的其他行一样对齐选定的行

ios - 如何在 WebService 主体中添加用户名和密码并获取 token

node.js - Firestore then() 函数在 set() 之后不执行

firebase - 网页中的 Flutter Firebase 实时数据库

java - 有人可以帮助我理解调用 Intent 来选择文件吗?

android - 外部库中的自定义 View 类不起作用

android - 如何查找日历内容提供者是否存在

iOS:setContentSize 导致我的整个 UIScrollView 框架跳转