【问题标题】:Expo notification click to action世博会通知点击采取行动
【发布时间】:2022-01-02 16:56:40
【问题描述】:
【问题讨论】:
标签:
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...
}
};