【问题标题】:Expo notification click to action世博会通知点击采取行动
【发布时间】:2022-01-02 16:56:40
【问题描述】:

当我收到推送通知并单击它将我重定向到屏幕、聊天等链接到推送通知时,我似乎找不到解决方案。

我也想在旁边加个方形图,找不到答案。

推送通知是从 NodeJS 服务器发送的,我查看了文档并搜索了互联网,但没有找到任何感兴趣的内容。

https://docs.expo.dev/versions/latest/sdk/notifications/#managing-notification-categories-interactive-notifications

https://github.com/expo/expo-server-sdk-node

提前感谢您的回答❤️

【问题讨论】:

    标签: javascript node.js react-native push-notification expo


    【解决方案1】:

    我不太确定方形图像,但为了处理重定向,您可以查看来自 expo 的文档:https://docs.expo.dev/push-notifications/receiving-notifications/

    然后,您可以通过消息上的 data 属性传递重定向所需的数据(即 notification_type、相关 id 等)(这将需要在创建消息的任何地方完成,从您的问题来自节点api):

    messages.push({
      to: pushToken,
      body: 'This is a test notification',
      data: { notification_type: 'something', id: 'something_else' },
    });
    

    然后由您决定如何根据您提供的额外数据处理该消息。

    例如,以上面链接中提供的代码为例,你可以有一个句柄函数如下:

    _handleNotification = response => {
    
        const data = response.notification.request.content;
        if (data.type === "new_message") {
           // navigate to MessageScreen with data.id as param
        } else {
           // do something else based on the type or...
        }
    };
    

    【讨论】:

    • 完美,我会试试的!谢谢你的回答?
    • 如果对您有帮助,请您将答案标记为已接受。
    猜你喜欢
    • 2019-03-25
    • 2021-03-02
    • 1970-01-01
    • 2019-08-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    相关资源
    最近更新 更多