我使用fcm发送推送通知到移动设备,包括ios和android。我在firestore中有一个表,其中有注册用户的设备ID。我在那个表中循环并向移动设备发送推送通知。我正在使用以下代码进行推送通知。
const sendNotification = (deviceId, userId) => {
return new Promise((resolve, reject) => {
let message = {
notification: {
title: 'TITLE',
body: `notification is sent to ${userId}`
}
};
let options = {
contentAvailable: true,
priority: "high",
timeToLive: 60 * 60 * 24
};
firebase.messaging().sendToDevice(deviceId, message, options)
.then(function (response) {
resolve({
message: `Successfully sent message`
})
console.log(`notification sent to ${userId}`);
})
.catch(function (error) {
reject({
message: "There is an issue sending push notification"
})
console.log('Error sending message:', error);
});
});
};
问题是通知已成功发送到所有设备,但并非所有设备都接收到。有时它在设备A上传递,当我重新运行代码时,推送通知不会传递到该设备。
有时所有设备都会收到推送通知,有时没有任何设备收到任何推送通知。
我在打电话
sendNotification