杀死应用程序后,我收到通知,但以下代码在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");
}
}
您必须添加通知代码,如下所示:
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();
}