Typescript 在Ionic应用程序中保存FCM通知数据
我可以向我的应用程序发送通知。 如果我的应用正在运行,那么它可以保存传入的通知数据 如果我的应用程序关闭,我单击通知托盘上的通知,它会打开我的应用程序,但不会保存通知数据 关于在应用程序关闭时如何保存通知数据,有什么建议吗? 下面是代码Typescript 在Ionic应用程序中保存FCM通知数据,typescript,firebase,ionic-framework,firebase-cloud-messaging,cordova-plugin-fcm,Typescript,Firebase,Ionic Framework,Firebase Cloud Messaging,Cordova Plugin Fcm,我可以向我的应用程序发送通知。 如果我的应用正在运行,那么它可以保存传入的通知数据 如果我的应用程序关闭,我单击通知托盘上的通知,它会打开我的应用程序,但不会保存通知数据 关于在应用程序关闭时如何保存通知数据,有什么建议吗? 下面是代码 platform.ready().then(() => { fcm.onNotification().subscribe( data => { this.con.notification_title = data.notifi
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();
});
});
我已经删除了数据。无论发生什么情况,我都会检查以保存消息。希望这对某人有所帮助
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();
}