5

Moving to FCM from GCM.

In GCM, we can call getToken() method for multiple sender ids as below:

String senderIds = "112233445566,889922338899";
String token = instanceID.getToken(senderIds,
                        GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);

Q1 - After moving into FCM, will it remain same or I need to make any changes in order to get the token for multiple sender ids?

From this reference, I know that I can call getToken("senderIds1", "FCM") for each sender Id, but I want minimum code changes while moving into FCM.

Q2 Will below work for FCM (same like GCM) or I have to call getToken("senderIds1", "FCM"); getToken("senderIds2", "FCM")?

getToken("senderIds1, senderIds2", "FCM") 
Hey You
  • 303
  • 3
  • 16
  • I could not tag you. So, copy pasting the comment in the answer here: I asked a similar question [here](https://stackoverflow.com/questions/52189326/is-firebaseinstanceidgettokensenderids-fcm-supported-where-senderids-is-c). I am continuing my conversation with FCM support team. I will update you once I get the final confirmation from them. – garnet Sep 11 '18 at 14:27
  • 1
    I have decided to tag this post as a duplicate to the reference post you mentioned as it contains the official way of handling multiple sender Ids. @garnet Do let us know what is the Firebase team's feedback about this as well. Cheers! – AL. Sep 12 '18 at 19:35
  • @AL. Quoting response firebase from support team: Just got confirmation from our engineers that multiple senders isn't supported with the InstanceID or FirebaseInstanceId APIs. It looks like our server is returning an old version of the token in these cases as it assumes any requests for multiple senders are GoogleCloudMessaging.register ones. We will be fixing this on our end, but we don't have any ETAs yet on when this would be available. Meanwhile, to get a similar behavior, you should request a different token per sender ID. These won't conflict with each other. – garnet Sep 22 '18 at 19:08
  • @AL.Further clarification from support team when asked about backward compatibility: We have no plans to support multiple senders with the InstanceID or FirebaseInstanceId APIs. We will also work on updating our documentation regarding this to avoid confusion. Thanks for bringing that up. – garnet Sep 22 '18 at 19:08
  • @garnet Thanks for the update. With that quote, then the my updated answer is spot on. Cheers! – AL. Sep 24 '18 at 04:30

1 Answers1

6

Looking more into this function -- scanning the documents and viewing old posts -- I've decided to update this answer. Since the behavior itself existed way before FCM was officially released, a lot of things have already been updated (some deprecated) in the service (under the hood). An example of this is going way back to C2DM to GCM migration, the part where the tokens weren't interoperable was stated.

For using getToken() by passing comma-separated senderIds, seeing as it is not documented or is advised/mentioned in any official FCM documentation or statements, it is best to avoid using them and instead proceed with the official procedure -- by using getToken("senderId", "scope") for each sender and maintaining each of those tokens as needed.

Choosing to still use getToken() by passing comma-separated senderIds may probably produce unexpected behaviors in the future, so I strongly encourage developers to proceed with the suggested procedure in the duplicate post.

AL.
  • 36,815
  • 10
  • 142
  • 281
  • 1
    I asked a similar question [here](https://stackoverflow.com/questions/52189326/is-firebaseinstanceidgettokensenderids-fcm-supported-where-senderids-is-c). I am continuing my conversation with FCM support team. I will update you once I get the final confirmation from them. – garnet Sep 11 '18 at 14:16