FCM会为通知负载中的每个键添加前缀gcm.notification。
以下是负载样例的计算示例:
"to":"cgOtBDOGIEc:APA91bGrjdPtrnGr0sIl4c66Z3Xp-JTzUasIN5TzWy7DtNUf-BlGvF64iNOXFN68zFC6oTYHJbP6eQgzIZICcsmIUG-NP5cIXf8EyPNiIAvOFU27XDKFbI2vowMjsNmZQdmh",
"notification":{
"title":"Testing title from postman!",
"body":"Testing body from postman!",
"sound":"default",
"tickerText":"This is ticker text"
},
"data" : {
"Nick" : "Mario Test",
"body" : "great match!",
"Room" : "PortugalVSDenmark"
}
}
针对上述数据负载,
总长度 = 通知负载和数据负载的长度之和
数据负载的长度 = [键的长度 + 值的长度] = [Nick + body + Room] 和 [Mario Test + great match + PortugalVSDenmark] 的字节长度之和,即 12 + 39 = 51。
为计算通知负载,每个键都必须以 gcm.notification. 作为前缀。
对于通知负载中的每个键,Firebase 在内部添加 gcm.notification. 作为前缀,并且在计算长度时也考虑了这个前缀。
Length of Notification Payload = [ no.of keys * length of (gcm.notification.) + length of keys + length of values ]
= 4*17 + length of bytes of [ title + body + sound + tickerText ] + length of bytes of [ Testing title from postman! + Testing body from postman! + default + This is ticker text ]
= 68 + 24 +79
= 171 bytes
Total length of the payload = 51 + 171 = 222 bytes.
希望这能回答你的问题。