This is how I am calling sending message:
sendMessage() {
var key = 'VERY LONG KEY -dffdADFDFD-vdfDafd';
var to = 'VERY LONG KEY -ADEWerew-vdfDafd';
var notification = {
'title': 'Portugal vs. Denmark',
'body': '5 to 1'
};
fetch('https://fcm.googleapis.com/fcm/send', {
'method': 'POST',
'headers': {
'Authorization': 'key=' + key,
'Content-Type': 'application/json',
},
'body': JSON.stringify({
'to': to,
'notification': notification,
'data': {
'message': 'example'
}
})
}).then(function (response) {
console.log(response);
response.json().then(function (result) {
console.log(result);
})
}).catch(function (error) {
console.error(error);
})
}
This is my onMessage:
messaging.onMessage(function (payload) {
console.log("Message received. ", payload);
});
But it does not go into the above code block. Currently I am testing when the application is opened and it has focus.