【发布时间】:2020-04-22 08:41:23
【问题描述】:
我正在尝试在我的 ionic 应用程序 (ionic 5) 中添加带有 firebase 的通知。我遵循本教程:https://www.positronx.io/ionic-firebase-fcm-push-notification-tutorial-with-example/
我收到令牌,当我从 firebase 控制台发送通知时,通知会显示在手机(模拟器)上,但控制台中不会显示任何内容来处理通知点击...
我将 FCM 添加到 app.modules.ts 的提供中,并在 app.component.ts 中添加了以下代码
import { FCM } from "@ionic-native/fcm/ngx";
...
constructor(
...
private fcm: FCM
) {}
initializeApp() {
this.platform.ready().then(() => {
this.statusBar.styleDefault();
this.splashScreen.hide();
this.fcm.getToken().then(token => {
console.log(token);
});
this.fcm.onTokenRefresh().subscribe(token => {
console.log(token);
});
this.fcm.onNotification().subscribe(data => {
console.log(data);
if (data.wasTapped) {
console.log('Received in background');
} else {
console.log('Received in foreground');
}
});
if (token === null) {
this.msgService.presentToast(
"Impossible de configurer la reception des notifications"
);
}
// Observer.hasTokenFCM.next(token);
if (this.platform.is("ios") || this.platform.is("android")) {
// this.saveToken(token);
}
});
并且已经安装了以下插件: 离子cordova插件添加cordova-plugin-fcm-with-dependecy-updated npm install @ionic-native/fcm
cordova 插件列表: cordova-plugin-fcm-with-dependecy-updated 4.4.0 “Cordova FCM 推送插件”
在我的 package.json 中:
依赖: "@ionic-native/fcm": "^5.22.0", "cordova-plugin-fcm-with-dependecy-updated": "^4.1.1",
“cordova”->“插件”: “cordova-plugin-fcm-with-dependecy-updated”:{ "FCM_CORE_VERSION": "16.0.8", "FCM_VERSION": "18.0.0", "GRADLE_TOOLS_VERSION": "2.3.+", “GOOGLE_SERVICES_VERSION”:“3.0.0” },
非常感谢您知道为什么“this.fcm.onNotification.subscribe”从未被触发...
【问题讨论】:
标签: android firebase ionic-framework notifications firebase-cloud-messaging