如何重新获取数据点击推送通知使用React-Native?



In myReact-Native项目我已经实现了expo-push-notification模块,我可以说一切工作如预期,但我有问题,我不知道如何解决,当用户收到消息并点击它

1。我想重定向到一个特定的屏幕2. 我想重新获取数据并调用特定的API端点3.我也希望这个功能工作时,应用程序的前景或背景

我的项目是在Bare工作流。

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

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

在您的场景中,您需要使用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,
})
}
}

最新更新