cordova - 如何使用 Ionic 捕获移动通知?
问题描述
有没有办法使用 Ionic 或 Cordova 插件捕获在移动设备上收到的通知?
解决方案
import { FCM } from '@ionic-native/fcm/ngx';
constructor(private fcm: FCM) {}
...
this.fcm.subscribeToTopic('marketing');
this.fcm.getToken().then(token => {
backend.registerToken(token);
});
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){
console.log("Received in background");
} else {
console.log("Received in foreground");
};
});
this.fcm.onTokenRefresh().subscribe(token => {
backend.registerToken(token);
});
this.fcm.unsubscribeFromTopic('marketing');
推荐阅读
- javascript - 在反应状态下使用类实例
- android - 按钮的困难设计 - Android Studio
- azure-devops - Azure DevOps 代码覆盖率与 .coverage 用于 PR 和 Cobertura 以获取完整报告
- python - 如何使用 python 从 selenium 的下拉列表中选择一个项目?
- python - 编辑 settings.json 后无法在 VScode 中运行 python
- algorithm - 如何使用 BFS 在图中找到哈密顿循环?(条件是图正好是哈密顿)
- python - 我打印我的值,但它附加了初始值
- heroku - 从 heroku 日志生成 webstats
- c - 字符串的动态数组,但我检测到堆损坏
- javascript - YUP 验证 - 如何获取值