【发布时间】:2025-12-02 02:05:01
【问题描述】:
我正在尝试使用来自 api 的令牌数组向多个设备发送推送通知。当我只发送到一个对象时,推送通知会正确发送,但是当我通过一组对象发送时,它会在请求中给出错误 400。
//assembling the array of tokens coming from the api
let tokenArray = [];
this.dataObj.notification_tokens.map((item) => {
tokenArray.push({
to: item.push_token,
sound: "default",
title: this.dataObj.push_title,
body: this.dataObj.push_message,
});
});
//passing the array as a parameter of the Expo Push Notification request. I receive 400 error
await fetch("https://exp.host/--/api/v2/push/send", {
mode: "no-cors",
method: "POST",
headers: {
Accept: "application/json",
"Accept-encoding": "gzip, deflate",
"Content-Type": "application/json",
},
body: JSON.stringify(tokenArray),
}).then((res) => {
if (res) {
this.dataObj.push_title = "";
this.dataObj.push_message = "";
this.goSuccess("Push Notification sending!");
}
});
如果我将单个对象作为Expo请求的参数传递,则推送通知正常发送
【问题讨论】:
标签: javascript vue.js push-notification expo