Куда я отправлю фоновые сообщения - PullRequest
0 голосов
/ 22 февраля 2019

Я пытаюсь установить заголовок фонового сообщения на моей угловой веб-странице 6, но я не знаю, должен ли я отправлять параметры этому API https://fcm.googleapis.com/fcm/send?И из какого файла.

1 Ответ

0 голосов
/ 22 февраля 2019

Для 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

...