【问题标题】: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);
    });
    

    【讨论】:

      【解决方案2】:

      我不建议你使用 FCM 插件。它没有方法来管理您的应用中的通知(清除所有或清除一些特殊通知。

      最好使用phonegap-push-plugin或One Signal

      【讨论】:

        猜你喜欢
        • 2014-03-20
        • 2020-05-26
        • 1970-01-01
        • 1970-01-01
        • 2016-08-02
        • 1970-01-01
        • 2017-01-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多