使用 FCM 插件 here我正在使用 firebase 接收通知。
let ready=await this.platform.ready();
this.fcm.onNotification().subscribe((data)=>{
alertdata);
},(error)=>{console.log(`error ${error}`);
});
通知会在应用未运行时到达,并且在应用运行时也会得到妥善处理。
但是在应用关闭时点击通知只会打开应用。
我想知道如何编写功能,以便在点击通知时根据收到的有效负载采取自定义操作。
最佳答案
您可以使用 data.wasTapped 来设置功能
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){
console.log("Received in background");
} else {
console.log("Received in foreground");
};
});
在 if 条件下编写的代码将在点击通知时起作用,而在 else 条件下编写的代码将在应用程序处于前台时起作用。 您还可以通过在条件中提供功能来移动到特定页面
关于android - Ionic Firebase 在通知点击后获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46669199/