Firebase Cloud Messaging - Managing Registration Tokens

前端 未结 1 1672
有刺的猬
有刺的猬 2020-11-29 04:54

I\'m looking at implementing messaging between mobile and browser apps using Firebase cloud messaging and i have a few questions, that the docs don\'t seem to answer.

<
相关标签:
1条回答
  • 2020-11-29 05:13
    1. Do I have to unsubscribe the old token and subscribe the new token to topics?

    AFAIK, you don't have to unsubscribe the old token, since it will be discarded by FCM itself. For the new token, yes, you'll have to subscribe it to the topic you need. The usual thing is done (in Android) by having subscribeToTopic() in onTokenRefreshed().


    1. Do I have to remove the old token and add the new token to device groups?

    Yes. You have to handle the mapping/relationships for Device Group Messaging. See my answer here. This is different from topics. The token will be invalidated, but will be kept as part of the list of registration tokens for the corresponding registration key.

    It's why there's a possibility to receive a NotRegistred error on one of the tokens if you send to Device Group. :)


    1. Is it possible to get information about device groups/topics for a token?

    For Device Group Messaging (same with #2), the developer (you) have to manage these details yourself. For topics, you can use the InstanceID API. Specifically, set details parameter to true:

    [optional] boolean details: set this query parameter to true to get available IID token details, including connection information and FCM or GCM topic subscription information (if any) for the device associated with this token. When not specified, defaults to false.


    1. Can I add a token to a device group more than once?

    Ahmm. Yes. Do you mean the same token? If so, I haven't tried it yet. Might as well do some checking on the client side before adding.


    1. Can I subscribe a token to a topic more than once?

    If you mean re-subscribing, then yes. If you mean duplicate request to subscribe, I think the result would still be a success. No changes in behavior though.


    1. Will multiple subscriptions/additions of the same token result in receiving duplicate messages?

    Tested it out. You won't receive duplicate messages for both duplicate topic subscriptions and adding the same token to a device group. It seems that FCM ignores the request to subscribe/add a Registration token if it's already subscribed/added to a device group.

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