firebase.notifications()。getInitialNotification()在用户杀死IOS中的应用程序时不起作用

问题描述 投票:0回答:1

杀死应用程序后,我收到通知,但以下代码在IOS中不起作用。当用户通过通知进入应用程序时,我想将用户重定向到特定页面。

componentDidMount()
{
const notificationOpen: NotificationOpen = await firebase
     .notifications()
     .getInitialNotification();
   if (notificationOpen) {
    alert("getInitialNossssssssstification");

     if (this.state.isUser) {
       await AsyncStorage.setItem("getNotificationsKey", "true");
       // console.log("jkasghfghdfgj isUser true");
     } else {
       // console.log("jkasghfghdfgj isUser false");
     }
   } else {
     console.log("elseeeeeeee");
   }
}
react-native
1个回答
0
投票

您必须添加通知代码,如下所示:

componentDidMount() {
    this.notificationOpenedListener = firebase.notifications().onNotificationOpened((notification) => {
        alert("getInitialNossssssssstification");

        if (this.state.isUser) {
            await AsyncStorage.setItem("getNotificationsKey", "true");
            // console.log("jkasghfghdfgj isUser true");
        } else {
            // console.log("jkasghfghdfgj isUser false");
        }
    });
}

componentWillUnmount() {
    this.notificationOpenedListener();
}
© www.soinside.com 2019 - 2024. All rights reserved.