【问题标题】:iOS application closes with no error when trying to retrieve push message data attributeiOS 应用程序在尝试检索推送消息数据属性时关闭且没有错误
【发布时间】:2018-08-09 16:55:53
【问题描述】:

我正在使用react-native-firebase 向应用程序发送推送消息,它看起来很棒!另外,我需要接收部分数据,所以发送类似这样的数据

$request_body = [

    'to' => $TOKEN_ID,
    'notification' => [

        'title' => 'Title',
        'body' => 'Body',
        'sound' => 'default',
    ],
    'data' => [

        'key' => 'value',
    ],
];

我正在尝试收听打开的推送消息事件,如下所示

this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notificationOpen) => {

    const notification = notificationOpen.notification;
    const data = notificationOpen.data;

    setTimeout(() => {

        Alert.alert(data.key);
    }, 5000);
});

5 秒后,应用程序关闭,没有任何错误消息。如果将Alert.alert(data.key); 更改为Alert.alert(notification.title); 应用程序工作正常并显示警报。有人可以向我解释一下,为什么无法正常检索数据?

【问题讨论】:

    标签: firebase react-native push-notification firebase-cloud-messaging


    【解决方案1】:

    经过一番研究,我找到了解决办法

    const data = notification.data;
    

    const data = notificationOpen.notification.data;
    

    【讨论】:

      猜你喜欢
      • 2021-10-30
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-03
      • 2018-08-15
      相关资源
      最近更新 更多