FCM通知

时间:2020-07-02 06:28:45

标签: javascript node.js firebase-cloud-messaging backend

我想向多个设备令牌发送通知。 如果我将其发送到单个设备令牌,则可以正常工作。

当我尝试发送到多个设备时,出现错误。因此,我将to的键更改为registration_ids,虽然可以正常工作,但是仍然出现以下错误:

TypeError:无法在字符串'{“ multicast_id”:6699347387645145001,“ success”:1,“ failure”:1,“ canonical_ids”:0,“ results”:[{“ message_id”:“上创建属性'isCatch' 0:1593672479225606%772927ea772927ea“},{” error“:” NotRegistered“}]}'

我正在使用fcm-node。

let token = dbCall()
for (let i =0; i < token.length ; i++){
     sendToken.push(token[i].token)
}

var message = {
            to:token[0].token,      // its working fine when i am sending to one deviceToken
            to: sendToken           // its an array of deviceToken its not working
            notification: {
                body: notificationData.message,
                title: notificationData.title,
            },
            data: {
                type: notificationData.type,
                title: notificationData.title,
                message: notificationData.message,
                designOrderId : notificationData.designOrderId,
                inboxCount: token[0].inboxCount,
            }
        };

return new Promise((resolve, reject) => {
            fcm.send(message, function(err, response) {
                if (err) {
                    console.log('notifyerr----->', err);
                    reject(err);
                } else {
                    // console.log('notifyresponse----->', response);
                    resolve(response);
                }
            })
        });

0 个答案:

没有答案