我将在哪里发送后台消息选项

时间:2019-02-22 06:40:07

标签: angular firebase firebase-cloud-messaging angularfire

我正在尝试在我的angular 6网页中设置背景消息标题,但是我不知道是否必须向该API this发送选项吗?以及哪个文件。

1 个答案:

答案 0 :(得分:0)

对于FCM,您需要在根文件夹中创建文件firebase-messaging-sw.js, 然后使用firebase.messaging()

获取用户令牌
let messaging=firebase.messaging();
messaging.requestPermission().then(function(){ return messaging.getToken();})

然后使用

https://fcm.googleapis.com/fcm/send发送发帖请求
//POST: https://fcm.googleapis.com/fcm/send
//HEADER: Content-Type: application/json
//HEADER: Authorization: key=AIzaSy*******************
{
  "notification":{
    "title":"Notification title",
    "body":"Notification body",
    "sound":"default",
    "click_action":"FCM_PLUGIN_ACTIVITY",
    "icon":"fcm_push_icon"
  },
  "data":{
    "param1":"value1",
    "param2":"value2"
  },
    "to":"/topics/topicExample",
    "priority":"high",
    "restricted_package_name":""
}
//sound: optional field if you want sound with the notification
//click_action: must be present with the specified value for Android
//icon: white icon resource name for Android >5.0
//data: put any "param":"value" and retreive them in the JavaScript notification callback
//to: device token or /topic/topicExample
//priority: must be set to "high" for delivering notifications on closed iOS apps
//restricted_package_name: optional field if you want to send only to a restricted app package (i.e: com.myapp.test)

这是FCM https://github.com/andrehtissot/cordova-plugin-fcm-with-dependecy-updated#send-notification-payload-example-rest-api

的完整文档

别忘了包括Firebase消息库