我目前正在使用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] },
]]
根据文档,to
必须为string
或string[]
,并且您要在此处发送object
。
尝试将有效负载更改为
[
{
to: 'ExponentPushToken[some_push_token]',
sound: 'default',
body: 'This is a test notification',
data: { withSome: 'data' },
},
]