【问题标题】:Getting an "to" must be a string, "to" must be an array error for sendPushNotificationsAsync获取“to”必须是字符串,“to”必须是 sendPushNotificationsAsync 的数组错误
【发布时间】:2019-12-10 05:37:45
【问题描述】:

我目前正在使用expo-server-sdk发送多个推送通知,但收到以下错误:

{ 错误:“值”必须是对象,位置 0 的“值”失败 因为 [child “to” 失败,因为 [“to” 必须是字符串,“to” 必须是 一个数组]]。

有效的推送令牌被传递给 expo.chunkPushNotifications,但是当块被传递给 expo.sendPushNotificationsAsync(chunk) 时,我收到了上面提到的错误消息:

(async () => {
  for (let chunk of chunks) {
    try {
      let ticketChunk = await expo.sendPushNotificationsAsync(chunk);
      tickets.push(...ticketChunk);
    } catch (error) {
      console.error(error);
    }
  }
})();

块的形式如下:

[ { to:
     { notificationToken: 'ExponentPushToken[some_push_token]' },
    sound: 'default',
    body: 'This is a test notification',
    data: { withSome: 'data' } },
]

这意味着块位于对象数组的数组中:

[ [ { to: [Object],
      sound: 'default',
      body: 'This is a test notification',
      data: [Object] },
]]

【问题讨论】:

    标签: javascript reactjs react-native push-notification expo


    【解决方案1】:

    根据文档,to 必须是 stringstring[],而您在此处发送 object

    尝试将您的有效负载更改为

        [
            {
                to: 'ExponentPushToken[some_push_token]',
                sound: 'default',
                body: 'This is a test notification',
                data: { withSome: 'data' },
            },
        ]
    
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-12-01
      • 2022-07-14
      • 2012-01-03
      • 1970-01-01
      • 1970-01-01
      • 2021-11-13
      • 2017-02-23
      相关资源
      最近更新 更多