Push Notification with Firebase + business rules

Asked

Viewed 256 times

2

I have to receive push notification from firebase, but it is not for all phones that these notifications will be sent. My app checks for changes in contracts, the user reports a number of CPF and the app searches the database for information about contracts under that CPF, and those contracts are changed frequently. So I wanted the user to receive notification in the app when some contract under the informed CPF was modified. I have thought to push to all phones, and somehow in Ionic show push show only if the CPF is user, but I found very wrong this solution.

1 answer

2


Try the following, the moment the user register has to generate a token fcm for him:

this.fcm.getToken().then(token => {
  console.log(token);
  //Aqui você pode armazenar esse token em algum lugar (Local Storage) e depois na hora de criar o usuário você passa o mesmo.
});

Then when sending the push just go through the CPF list you want, pick up and send the messages according to each token.

References: https://ionicframework.com/docs/native/fcm/

https://firebase.google.com/docs/cloud-messaging/http-server-ref

  • I get it, more or less. How in firebase would I relate the token that was registered to create this token and Cpf link?? Let’s assume: app generated a token = 34 , app that has CPF 2222, created user by the generated token. As in firebase I will know that for CPF 222 I have to send to token app 34?

  • 2

    Ah, I think I get it now. I would generate a token in fcm, then when creating the account I would write that token there in firebase, then I would scan the token document and send it to the registrants for that CPF? Is that it? I think it really works. In firebase you can do this with functions, neh? I’ll read the references you gave me. Vlws.

  • 2

    That’s right hehe, take a look. Just you attach the token to a user

Browser other questions tagged

You are not signed in. Login or sign up in order to post.