FCM | Multiple Sender ID [duplicate]

2019-06-12 12:15发布

问题:

This question already has an answer here:

  • How to put multiple project_number/sender id in google-services.json 3 answers

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") 

回答1:

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.