Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the maximum length of an FCM registration ID token?

Working with the "new" Firebase Cloud Messaging, I would like to reliably save client device registration_id tokens to the local server database so that the server software can send them push notifications.

What is the smallest size of database field that I should use to save 100% of client registration tokens generated?

I have found two different libraries that use TextField and VarChar(255) but nothing categorically defining the max length. In addition, I would like the server code to do a quick length check when receiving tokens to ensure they "look" right - what would be a good min length and set of characters to check for?

like image 422
jamesc Avatar asked Oct 10 '16 13:10

jamesc


People also ask

Is there any limit for FCM?

You can send up to 240 messages/minute and 5,000 messages/hour to a single device.

What is registration ID in FCM?

The registration_ids parameter refers to the Registration Tokens you want to add in that specific Device Group. Described as: An ID generated by the FCM SDK for each client app instance. Required for single device and device group messaging. Note that registration tokens must be kept secret.

Does FCM registration token change?

Similarly to how GCM works, the FCM token can change due to token-rotation. Note: the token rotation is a rare-event. Don't expect to see it often. But still, if you care about the token you should implement onTokenRefresh() to be informed of changes.

Is FCM ID unique?

Yes, they are unique but they are not constant.


2 Answers

I think this part of FCM is still the same as GCM. Therefore, you should refer to this answer by @TrevorJohns:

The documentation doesn't specify any pattern, therefore any valid string is allowed. The format may change in the future; please do not validate this input against any pattern, as this may cause your app to break if this happens.

As with the "registration_id" field, the upper bound on size is the max size for a cookie, which is 4K (4096 bytes).

Emphasizing on the The format may change in the future part, I would suggest to stay safe and have a beyond the usual max (mentioned above) length. Since the format and length of a registration token may also vary.

For the usual length and characters, you can refer to these two answers the latter being much more definitive:

I hasn't seen any official information about format of GCM registrationId, but I've analyzed our database of such IDs and can make following conclusions:

  • in most cases length of a registrationID equals 162 symbols, but can be variations to 119 symbols, maybe other lengths too;
  • it consists only from this chars: [0-9a-zA-Z\-\_]*
  • every regID contains one or both of "delimiters": - (minus) or _ (underline)
like image 93
AL. Avatar answered Oct 19 '22 02:10

AL.


I am now using Firebase Cloud Messaging instead of GCM.

The length of the registration_id I've got is 152.

I've also got ":" at the very beginning each time like what jamesc mentioned (e.g. bk3RNwTe3H0:CI2k_HHwgIpoDKCIZvvDMExUdFQ3P1).

I make the token as varchar(255) which is working for me.

However, the length of registration_id has no relationship with size of 4k. You are allowed to send whatever size of the data through network. Usually, cookies are limited to 4096 bytes, which consist of name, value, expiry date etc.

like image 44
Fred Lai Avatar answered Oct 19 '22 02:10

Fred Lai