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

后端 未结 3 1736
南笙
南笙 2020-11-30 05:40

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 s

相关标签:
3条回答
  • 2020-11-30 06:18

    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)
    0 讨论(0)
  • 2020-11-30 06:22

    I don't think the upper limit for a registration ID is 4K. It should be safe to assume that it is much lower than that.

    The upper limit for a notification payload is 4KB (link), and the notification payload includes the token (link). Since the payload also needs to include the title, body, and other data too, the registration ID should be small.

    That's what I understand from the docs ¯\_(ツ)_/¯

    The last tokens I got were 163-chars long. I think it's safe to assume that they will never exceed 255 chars.

    0 讨论(0)
  • 2020-11-30 06:23

    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.

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