世博会推送通知点击事件

时间:2019-07-18 14:36:24

标签: react-native push-notification expo

在文档中找不到如何处理通知的点击 订阅通知只有一种方法。

Notifications.addListener(this._handleNotification);

2 个答案:

答案 0 :(得分:0)

您必须使用“来源”属性来确定是否接收或选择了通知。

_handleNotification = (notification) => {
    if(notification.origin === 'received') {
        // after receive push notification code
    }else if(notification.origin === 'selected'){
        // after click code
    }
}

答案 1 :(得分:0)

对于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);
});