我们使用 Firebase 向应用程序发送消息已经有一段时间了,但由于旧版已停用,因此必须升级到 v1 平台。我们能够接收消息,但现在当我们发送时,警报声音(通知)不会响起。我认为这与我们如何发送有效负载有关。
这是我们过去发送的内容(值以井号表示):
<cfset bodyData = { "to": "#get_messages.UDID#",
"priority": "high",
"notification" : {
"title": "test Crisis",
"body" : "#body#",
"EMB_id": "#get_messages.EMB_id#",
"message_log_id": "#get_messages.message_log_id#",
"reference_alertID": "#get_messages.reference_alertID#",
"recipient": "#recipient#",
"recipient_firstname": "#get_recipient.sub_firstname#",
"recipient_lastname": "#get_recipient.sub_lastname#",
"recipient_profile_image": "http://crisis.wensnetwork.com/wens_crisis/app_profiles/#get_recipient.app_profile_image#",
"reply_resolve": "#get_messages.reply_resolve#",
"reply_public": "#get_messages.reply_public#",
"msg_type": "1",
"tracker": "#get_messages.tracker#",
"app_message_id": "#get_messages.app_message_id#",
"content_available": "true",
"sound": "#sounds#",
"content_available": "1",
"apns-priority": "5",
"image": ""
},
"data" : {
"title": "test Crisis",
"body" : "#body#",
"EMB_id": "#get_messages.EMB_id#",
"message_log_id": "#get_messages.message_log_id#",
"reference_alertID": "#get_messages.reference_alertID#",
"recipient": "#recipient#",
"recipient_firstname": "#get_recipient.sub_firstname#",
"recipient_lastname": "#get_recipient.sub_lastname#",
"recipient_profile_image": "http://test.com/test_crisis/app_profiles/#get_recipient.app_profile_image#",
"reply_resolve": "#get_messages.reply_resolve#",
"reply_public": "#get_messages.reply_public#",
"msg_type": "1",
"tracker": "#get_messages.tracker#",
"app_message_id": "#get_messages.app_message_id#",
"content_available": "true",
"sound": "#sounds#",
"content_available": "1",
"apns-priority": "5",
"image": ""
}
} >
这在旧平台上运行得很好。
但现在我们必须更改为新的 JSON 发布结构:
<cfset bodyData = '{ "message": {
"token": "#get_messages.UDID#",
"notification": {
"title": "test Crisis",
"body": "#body#",
"image": ""
},
"data": {
"title": "test Crisis",
"body": "#body#",
"EMB_id": "#get_messages.EMB_id#",
"sound": "#sounds#",
"message_log_id": "#get_messages.message_log_id#",
"reference_alertID": "#get_messages.reference_alertID#",
"recipient": "#recipient#",
"recipient_firstname": "#get_recipient.sub_firstname#",
"recipient_lastname": "#get_recipient.sub_lastname#",
"recipient_profile_image": "http://test.com/test_crisis/app_profiles/#get_recipient.app_profile_image#",
"reply_resolve": "#get_messages.reply_resolve#",
"reply_public": "#get_messages.reply_public#",
"msg_type": "1",
"tracker": "#get_messages.tracker#",
"app_message_id": "#get_messages.app_message_id#",
"content_available": "1",
"apns-priority": "5",
"image": ""
}
}
}' >
最大的区别是我看到没有任何内容分配给“通知”标签,并且怀疑铃声不会通过。 “声音”标签是我们添加要播放的音调的地方。但什么也没发生。
当然,这需要更多的研究和阅读,但我找到了。这是其他遇到过的人的答案。
除了通知和数据之外,我没有使用以下标签:
"apns": {
"payload": {
"aps": {
"sound": "#sounds#"
}
}
}
所以这是完整的代码,添加了:
<cfset bodyData = '{ "message": {
"token": "#get_messages.UDID#",
"notification": {
"title": "test Crisis",
"body": "#body#",
"image": ""
},
"apns": {
"payload": {
"aps": {
"sound": "#sounds#"
}
}
},
"data": {
"title": "test Crisis",
"body": "#body#",
"EMB_id": "#get_messages.EMB_id#",
"sound": "#sounds#",
"message_log_id": "#get_messages.message_log_id#",
"reference_alertID": "#get_messages.reference_alertID#",
"recipient": "#recipient#",
"recipient_firstname": "#get_recipient.sub_firstname#",
"recipient_lastname": "#get_recipient.sub_lastname#",
"recipient_profile_image": "http://test.com/wens_crisis/app_profiles/#get_recipient.app_profile_image#",
"reply_resolve": "#get_messages.reply_resolve#",
"reply_public": "#get_messages.reply_public#",
"msg_type": "1",
"tracker": "#get_messages.tracker#",
"app_message_id": "#get_messages.app_message_id#",
"content_available": "1",
"apns-priority": "5",
"image": ""
}
}
}' >