我将在哪里发送背景信息选项

问题描述 投票:0回答:1

我正在尝试在我的角度6网页中设置背景消息标题,但我不知道我必须向这个api https://fcm.googleapis.com/fcm/send发送选项吗?从哪个文件。

angular firebase firebase-cloud-messaging angularfire
1个回答
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消息库

© www.soinside.com 2019 - 2024. All rights reserved.