我们目前已经编写了一个Ionic和Firebase项目。在这个项目中,我们希望使用推送通知。但我们的麻烦是:我们正在寻找一个推送通知插件,就像WhatsApp应用程序。例如,当我们向一个人发送消息时,我们希望通知发到我们发短信的那个人,而不是每个人。但我们找不到一种免费的方法来做到这一点。你有什么意见建议?谢谢。
发布于 2019-07-12 02:51:59
使用cordova-和ionic-native的Firebase云消息传递插件: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);
});发布于 2019-10-17 22:14:12
我不建议你使用FCM插件。它没有方法来管理您的应用程序中的通知(清除所有或清除一些特殊的通知。
最好使用phonegap-push-plugin或一个信号
https://stackoverflow.com/questions/56975392
复制相似问题