【发布时间】:2018-12-02 11:39:30
【问题描述】:
我有一个简单的 Ionic 实现 (Android) 来接收来自 FCM 的消息。 当从 Firebase 控制台发送消息时,通知会到达并显示警报,但不会显示消息数据。
这是代码(app.component.ts):
constructor(platform: Platform, statusBar: StatusBar, splashScreen: SplashScreen, public fcm: FCM, private alertCtrl: AlertController) {
this.fcm.subscribeToTopic('all');
platform.ready().then(() => {
this.fcm.getToken().then(token => {
console.log(token);
let alert = this.alertCtrl.create({
title: '¡New token!',
message: token,
buttons: [
{
text: 'Cancel',
role: 'cancel',
handler: () => {
console.log('Cancel');
}
},
{
text: 'OK',
handler: () => {
console.log('OK');
this.navCtrl.push('DetailPage');
}
}
]
});
alert.present();
});
this.fcm.onNotification().subscribe(data => {
alert('message received');
if(data.wasTapped) {
console.log(data);
console.info("Received in background");
} else {
// console.log(data);
console.info("Received in foreground");
};
});
例如,当消息从 Firebase 控制台发送时:
- 消息文本:这是一个测试!
- 可选标签:新消息。
显示应用程序中的alert('message received'),但是console.log(data)到fcm.onNotification().subscribe()的输出是:
> {wasTapped: false}
{"wasTapped": false}
如何获取消息数据?任何想法? 谢谢。
【问题讨论】:
-
但是当你在前台收到console.log()时有注释
标签: firebase ionic-framework ionic2 firebase-cloud-messaging cordova-plugin-fcm