1

I've never used FCM (or GCM) before, but I'm looking into writing an app that will involve publishing messages to multiple devices, and "topics" seem to be a good approach.

From what I've read of the docs so far, my app server will publish messages to a named topic, so presumably it doesn't need to know about registration tokens for the recipient devices?

I believe a registration token must be specified when subscribing to a topic, so I guess a recipient device must still request a token before it can subscribe. What happens when the token expires - does the app have to subscribe to the topic again, using the new token?

AL.
  • 36,815
  • 10
  • 142
  • 281
Andrew Stephens
  • 9,413
  • 6
  • 76
  • 152

1 Answers1

1

so presumably it doesn't need to know about registration tokens for the recipient devices?

No. It doesn't. But I would strongly suggest for you to save the registration tokens so you can keep track of them using the Diagnostics tool in the future.

What happens when the token expires - does the app have to subscribe to the topic again, using the new token?

In Android, you simply have to call

FirebaseMessaging.getInstance().subscribeToTopic(<topic_name_here>);

to subscribe the device to a topic. The way on how I understand this works is explained here, where the FirebaseMessaging class calls an instance of the FirebaseInstanceId and (presumably) subscribe the currently active registration token.

According to @DiegoGiorgini's answer here, the topic subscriptions are maintained if the token is refreshed.

AFAIK (haven't encountered it yet), the corresponding registration token should be re-subscribed. Depending on where you implement the subscription.

I would suggest having it on start of the app itself. Better if you'd have a list of topics (should there be more than one) on your App Server, and perhaps make use of the InstanceID API to do the re-subscription if needed.

Community
  • 1
  • 1
AL.
  • 36,815
  • 10
  • 142
  • 281
  • Many thanks. So the device doesn't need to explicitly pass its token in the call to subscribe? (I thought it did, but perhaps that was GCM, not FCM). – Andrew Stephens Dec 22 '16 at 08:11
  • 1
    @AndrewStephens Nope. Just call the `subscribeToTopic()` from the client-side and it'll use the corresponding token. Cheers! – AL. Dec 22 '16 at 08:19