-3

I want to have FCM in my app in the way It allows users to exchange messages between them. But I've been days struggling with the token thing. I have read a lot of posts but a lot of people talk about removing the token when the user logs in, but I don't want to just send messages between users logged in. What I want is between registered users, so how can I distinguish between users, how to map them with their token, because the easiest is to remove and create token whenever a user logged in, so you map user-token but with this idea how do I know the token of a user who hasn't logged in?

AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    Possible duplicate of [How to send Device to device notification by using FCM without using XMPP or any other script.?](http://stackoverflow.com/questions/38432243/how-to-send-device-to-device-notification-by-using-fcm-without-using-xmpp-or-any) – Dmytro Rostopira Mar 03 '17 at 11:55
  • The problem is that they make it so complex with security stuff. Here thanks to the answer below I understood that the topic can fix the problem to distinguish the different users. – Javier Uribe Mar 03 '17 at 13:26

1 Answers1

1

I also have similar problem. What i am doing is when user signup for my app it also generated a FCM token and save this linking with the user id so when i have to send msg A , I search for the user A and then get the Token of A and then send the msg. This thing can only be achieve by FCM Server.

Have a look at the documentation. Here is also a great blog for setting up a FCM server in java.

Farrukh Faizy
  • 1,203
  • 2
  • 18
  • 30
  • So when the user A logs in, would I have to replace the token as well? – Javier Uribe Mar 03 '17 at 10:40
  • No there no need, I write when user sign up for the app not logged in – Farrukh Faizy Mar 03 '17 at 10:41
  • Ok, and what happens if the user reinstalls the app? – Javier Uribe Mar 03 '17 at 10:43
  • I am expecting you are saving your tokens to your firebase database! Uninstall the app doesnot lead you to remove your data from db – Farrukh Faizy Mar 03 '17 at 10:46
  • The problem I see is that if a different user wanted to use the same phone the token would be the same. The problem is that I need something to map user-token, thats why the login was usefull, but registration is only donde once. Uninstalling the app provokes the removal of the token, thats why I asked, because I'd have to replace the token again – Javier Uribe Mar 03 '17 at 10:46
  • You have to tweak things and make some logic – Farrukh Faizy Mar 03 '17 at 10:48
  • I need a mechanism that guarantees me mapping between users, so as the token doesn't change between users in the same phone. All the users who used the same phone as they are not registrating to get in, they all would have the same token – Javier Uribe Mar 03 '17 at 10:49
  • Create unique topic for each user for example topicuseremail and send messages to topic. – eurosecom Mar 03 '17 at 10:56
  • I see, you helped a lot, thank you so much – Javier Uribe Mar 03 '17 at 11:00