【发布时间】:2016-12-08 07:20:31
【问题描述】:
我正在使用带有HTTP native module 的 Ionic 2 向 FCM 服务器发出发布请求以获取推送通知。我使用的代码是:
HTTP.post(
"https://fcm.googleapis.com/fcm/send",
{
"notification": {
"title": "Notification title",
"body": "Notification body",
"sound": "default",
"click_action": "FCM_PLUGIN_ACTIVITY",
"icon": "fcm_push_icon"
},
"data": {
"hello": "This is a Firebase Cloud Messagin hbhj g Device Gr new v Message!",
},
"to": "device token",
},
{
Authorization: {
key: "AUTHORIZATION KEY HERE"
}
})
它给了我一个错误:
Unimplemented console API: Unhandled Promise rejection:
Unimplemented console API: Error: Uncaught (in promise): [object Object]
我用 Postman 尝试了发布请求,它可以很好地传递推送通知。
Postman 的代码是:
POST /fcm/send HTTP/1.1
Host: fcm.googleapis.com
Content-Type: application/json
Authorization: key=Authorisation Key
Cache-Control: no-cache
Postman-Token: 446e253b-179a-d19b-21ea-82d9bb5d4e1c
{
"to": "Device Token",
"data": {
"hello": "This is a Firebase Cloud Messagin hbhj g Device Gr new v Message!",
}
"notification":{
"title":"Notification title",
"body":"Notification body",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
}
问题:
我无法将
content-type添加到 HTTP 发布请求的标头中,但它适用于邮递员。如果我尝试添加
function(response) {以从服务器获取响应,则会出现错误。相同的文档位于https://github.com/wymsee/cordova-HTTP
【问题讨论】:
标签: http push-notification ionic2 cordova-plugins firebase-cloud-messaging