3

We currently have an Ionic and Firebase project that we coded. In this project, we want to use push notifications. But our trouble is: We are looking for a push notification plugin, like WhatsApp application. For example, when we send a message to a person, we want the notification to go to the person we're texting from, not everyone. But we couldn't find a free way to do that. Do you have any suggestions? Thank you.

2 Answers2

3

Firebase Cloud Messaging By using cordova-plugin and 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);
});
Alam
  • 303
  • 1
  • 3
  • 14
1

I don't recommend you to use FCM plugin. It has no methods to manage your notifications in your app (clear all or clear some special notification.

It is better to use phonegap-push-plugin or One Signal

Karpov Vladimir
  • 140
  • 1
  • 1
  • 9