send cloud message (FCM) multiple devices single user

前端 未结 1 1683
予麋鹿
予麋鹿 2021-01-26 07:31

I have an application which is already built. Now I want to use FCM to send messages between server and users. As I understand each device has its own token which I can use

相关标签:
1条回答
  • 2021-01-26 07:48

    You need to change your DB and add ability to save all device tokens from one user. Then you need to call this Firebase api https://fcm.googleapis.com/fcm/send as many times as the tokens user have. Here the official documentation.

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

    To update device specific token when it is changed on client side, you also have to bound that token with the deviceID, so to have that you need to pass the DeviceId to the server when passing the Firebase token. As deviceID can serve Android unique deviceID, or the id that provides Firebase in client side FirebaseInstanceId.getInstance().id. And here how to get Android deviceID

    Is there a unique Android device ID?

    If you use access_token for login the user, as another alternative, you can bound firebase token with user access_token, as it is unique for any device the user logged in.

    0 讨论(0)
提交回复
热议问题