我收到通知,但是当应用程序在下面的后台运行时,代码在IOS中不起作用。当用户通过通知进入应用程序时,我想将用户重定向到特定页面。 我遵循以下过程enter link description here
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");
}
}
答案 0 :(得分: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();
}