我们可以使用 fcm-node 推送通知将对象发送到数据中吗

Can we send object into data using fcm-node push notification

let messages = {
        
        registration_ids: tokenId,

        notification: {
          title: 'WebServer',
          body: 'Message from center'
        },

        data: { result: { type: 'add', data : 'New Record' }, sender: {'first_name': 'James', 'last_name': 'Antony' } },
      };

      fcm.send(messages, function (err, response) {
        if (err) {
          return err
          console.log("Something has gone wrong!", err);
        } else {
          console.log("Successfully sent with response: ", response.results);
         
        }
      });

我们能否在数据中发送对象,即结果可以提供类型和消息。

如果我把对象放在里面,它不会发送通知,但如果我做 toString() 它确实有效,但在移动端它显示 [object][object]。

我们怎样才能让它正确。

data 节点只能包含字符串值。它不能包含更复杂的值,例如对象。

如果您想发送更复杂的数据,请在您的消息中将其编码为字符串,然后在您的应用程序代码中对该字符串进行解码。例如,您可以使用 JSON.stringifyJSON.parse 发送 JSON 个对象。