我正在尝试在我的angular 6网页中设置背景消息标题,但是我不知道是否必须向该API this发送选项吗?以及哪个文件。
答案 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)
的完整文档
别忘了包括Firebase消息库