如何在Firebase推送通知中捕获多播响应?

时间:2017-04-29 04:52:48

标签: firebase push-notification google-cloud-messaging fetch-api web-notifications

使用Firebase发送推送通知后我得到的回复的屏幕截图。我在第二个响应流中获得multicast_id,success:0等。如何捕捉它? The second response shows whether the push notification is delivered or not. How to capture it?

1 个答案:

答案 0 :(得分:0)

找到答案!!

  //This function to sends push notification to users
for (var i = 0; i <= endUsersList.length - 1; i++)
{
fetch('https://fcm.googleapis.com/fcm/send', {
    'method': 'POST',
    'headers': {
        'Authorization': 'key=' + key,
        'Content-Type': 'application/json'
    },
    'body': JSON.stringify({
        'notification': notification,
        'to': endUsersList[i]
    }),
}).then(function (response) {
    if (response.status !== 200) {
        console.log('Looks like there was a problem. Status Code: ' +
          response.status);
        return;
    }
    // Examine the text in the response  
    response.json().then(function (data) {
        console.log(data);
    });
}).catch(function (err) {
    console.log('Fetch Error :-S', err);
})