“ to”必须是字符串,“ to”必须是sendPushNotificationsAsync的数组错误

问题描述 投票:1回答:1

我目前正在使用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' } },
]

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

[ [ { to: [Object],
      sound: 'default',
      body: 'This is a test notification',
      data: [Object] },
]]
javascript reactjs react-native push-notification expo
1个回答
0
投票

根据文档,to必须为stringstring[],并且您要在此处发送object

尝试将有效负载更改为

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

© www.soinside.com 2019 - 2024. All rights reserved.