【问题标题】:Is there way to use push notifications in our ionic 4 project?有没有办法在我们的 ionic 4 项目中使用推送通知?
【发布时间】:2019-07-10 16:57:44
【问题描述】:
我们目前有一个我们编写的 Ionic 和 Firebase 项目。在这个项目中,我们要使用推送通知。但我们的麻烦是:
我们正在寻找一个推送通知插件,例如 WhatsApp 应用程序。例如,当我们向某人发送消息时,我们希望通知发送给我们发短信的人,而不是每个人。但我们找不到免费的方法来做到这一点。你有什么建议吗?谢谢。
【问题讨论】:
标签:
ionic-framework
push-notification
apple-push-notifications
ionic4
android-push-notification
【解决方案1】:
Firebase 云消息传递 通过使用 cordova-plugin 和 ionic-native:Ref. Url
import { FCM } from '@ionic-native/fcm/ngx';
constructor(private fcm: FCM) {}
this.fcm.getToken().then(token => {
//you can store device token in firebase, later you can target push notification from firebase console this token id
backend.registerToken(token);
});
this.fcm.onNotification().subscribe(data => {
if(data.wasTapped){ / * true , means the user tapped the notification from the notification tray and that’s how he opened the app. */
console.log("Received in background");
} else {// false , means that the app was in the foreground (meaning the user was inside the app at that moment)
console.log("Received in foreground");
};
});
this.fcm.onTokenRefresh().subscribe(token => {
//update device token
backend.registerToken(token);
});