我创建了一个小功能,可以向用户发送通知。令牌ID将从数据库中获取,并且通知应发送到该设备。即使该功能在控制台中绝对可以运行。即使发送通知,我也收到了设置的响应,但这对设备没有影响。 我正在尝试将通知发送到主要是Ipad的Iphone设备
代码在这里
exports.SendNotification = functions.firestore.document("UserData/{user_id}").onWrite((change, context) => {
const user_id = context.params.user_id;
console.log('We have a notification to send to :', user_id);
return admin.firestore().collection("UserData").doc(user_id).get()
.then(snapshot2 =>
{
const Message =snapshot2.data().msg;
const token_id =snapshot2.data().token_id;
console.log(" Message: ", Message);
console.log(" Token_id: ",token_id);
const payload =
{
notification:
{
title: "Notification",
body: "Hi this is to notify you",
icon: "default"
}
};
return admin.messaging().sendToDevice(token_id, payload)
.then(response =>
{
return console.log('Second notification is also send successfully');
});
});
});