当我没有检查previous.exists()时,我的firebase云函数被多次调用.我收到多个推送通知.
if (!event.data.exists()){
return;
}
if (event.data.previous.exists()){
return;
}
Run Code Online (Sandbox Code Playgroud)
但是当我检查它时,我没有得到推送通知.这是不工作的代码:我应该改变什么?
exports.sendShoppingListInvitationNotification = functions.database.ref('/invites/{id}/').onWrite(event => {
//get the snapshot of the written data
const snapshot = event.data;
if (!event.data.exists()){
return;
}
if (event.data.previous.exists()){
return;
}
//get snapshot values
console.log(snapshot.key);
const receiptToken = snapshot.child('receiptFcmToken').val();
const senderName = snapshot.child('senderNickname').val();
const inviteMessage = snapshot.child('inviteMessage').val();
const senderImage = snapshot.child('senderProfileImageURL').val();
//create Notification
const payload = {
notification: {
title: `Invitation from ${senderName}`,
body: `${inviteMessage}`,
icon: `${senderImage}`,
badge: '1',
sound: 'default',
}
};
//send a notification to …Run Code Online (Sandbox Code Playgroud)