【问题标题】:How to refetch data on click push notification using React-Native?如何使用 React-Native 重新获取点击推送通知的数据?
【发布时间】:2022-06-14 16:44:55
【问题描述】:

在我的 React-Native 项目中,我实现了expo-push-notification 模块,我可以说一切都按预期工作,但是当用户收到一条消息时,我遇到了不知道如何解决的问题点击它

1.我想重定向到特定屏幕 2. 我想重新获取数据并调用特定的 API 端点 3.我也希望这个功能在App是前台或后台时也能正常工作

我的项目在 Bare 工作流程中。

经过多次研究,我找不到可以给我正确方向的提示。

使用 React-Native 实现这一目标有多现实?

【问题讨论】:

    标签: android ios react-native push-notification expo


    【解决方案1】:

    在您的场景中,您需要使用 addNotificationReceivedListener,该侦听器将在用户单击通知后触发,在该侦听器中您可以访问通知响应数据并导航到另一个屏幕。

    您可以在此处阅读更多信息https://docs.expo.dev/push-notifications/receiving-notifications/

    通知监听函数示例

    const handleNotificationResponse = (response: NotificationResponse) => {
        const { data } = response.notification.request.content
        if (data) {
            navigationRef?.current?.push('your_screen_name', {
                id: data?.id,
                otherImportantData: data.others,
              })
        }
      }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-05-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-11
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多