【发布时间】:2019-07-18 14:36:24
【问题描述】:
在文档中没有找到如何处理点击通知 只有一种方法可以订阅通知,仅此而已。
Notifications.addListener(this._handleNotification);
【问题讨论】:
标签: react-native push-notification expo
在文档中没有找到如何处理点击通知 只有一种方法可以订阅通知,仅此而已。
Notifications.addListener(this._handleNotification);
【问题讨论】:
标签: react-native push-notification expo
您必须使用“origin”属性来确定是否收到或选择了通知。
_handleNotification = (notification) => {
if(notification.origin === 'received') {
// after receive push notification code
}else if(notification.origin === 'selected'){
// after click code
}
}
【讨论】:
对于 ExpoSDK39 及更新版本,您可以查看https://docs.expo.io/versions/latest/sdk/notifications/
简单地说,您可以使用 Notifications.addNotificationResponseReceivedListener 并检查响应中的actionIdentifier 属性。
// adds a listener called whenever user interacts with a notification
// "actionIdentifier": "expo.modules.notifications.actions.DEFAULT", means user clicked the notification
responseListener.current = Notifications.addNotificationResponseReceivedListener(response => {
console.log("addNotificationResponseReceivedListener", response);
});
【讨论】: