gpt4 book ai didi

typescript - 在 Ionic App 中保存 FCM 通知数据

转载 作者:行者123 更新时间:2023-12-05 07:35:34 30 4
gpt4 key购买 nike

我可以向我的应用程序发送通知。如果我的应用程序正在运行,那么它能够保存传入通知数据

如果我的应用程序已关闭并且我单击通知托盘上的通知它会打开我的应用程序但不保存通知数据关于应用程序关闭时我们如何保存通知数据的任何建议? 下面是代码

    platform.ready().then(() => {


fcm.onNotification().subscribe( data => {
this.con.notification_title = data.notification_title;
this.con.notification_message = data.notification_message;
if(localStorage.getItem('oldmsg'))
{
this.temparr = JSON.parse(localStorage.getItem('oldmsg'));
this.temparr.push({"notification_title":this.con.notification_title,"notification_message": this.con.notification_message});
localStorage.setItem('oldmsg',JSON.stringify(this.temparr));
this.presentToast("You Recieved A Message!");

}
else{

this.temparr.push({"notification_title":this.con.notification_title,"notification_message": this.con.notification_message});
localStorage.setItem('oldmsg',JSON.stringify(this.temparr));
this.presentToast("You Recieved A Message!");

}
});

statusBar.styleDefault();
splashScreen.hide();

this.storage.get('introShow').then((result) => {

if(result){

this.navCtrl.setRoot(LoginPage);
this.storage.set('introShow', true);
} else {

this.navCtrl.setRoot(IntroPage);
this.storage.set('introShow', true);
}

this.listenToLoginEvents();
});


});

我已经删除了 data.wasTapped 检查以无论如何保存消息。

最佳答案

希望这对某人有帮助

        this.Onesignal.startInit(this.oneSignalAppId, this.sender_id);
this.Onesignal.inFocusDisplaying(this.Onesignal.OSInFocusDisplayOption.Notification);
this.Onesignal.handleNotificationReceived().subscribe(// when its received
data => {
if (localStorage.getItem('notifications')) {
this.temparr = JSON.parse(localStorage.getItem('notifications'));
this.temparr.push({body: data.payload.body,
title: data.payload.title,
type: data.payload.additionalData.type});
localStorage.setItem('notifications', JSON.stringify(this.temparr.reverse()));

this.events.publish('user:noti_done', {
user: 'done',
time: new Date()
});

} else {
this.temparr.push({body: data.payload.body,
title: data.payload.title,
type: data.payload.additionalData.type});
localStorage.setItem('notifications', JSON.stringify(this.temparr));

this.events.publish('user:noti_done', {
user: 'done',
time: new Date()
});
}
});

this.Onesignal.handleNotificationOpened().subscribe(data => {
console.log('handleNotificationOpened');
console.log(data);

});
this.Onesignal.endInit();
}

关于typescript - 在 Ionic App 中保存 FCM 通知数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49483811/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com