for(xxxxxx){
let pushSend = {
"user_id": xxxxx,
"title": title,
"content": content,
"payload": {
"oids":xxx
}
}
uniPush.sendMessage(pushSend)
.then(res=>{
console.log("push res:", res);
if(res.errCode){
console.log("推送失败:", res.errMsg);
}
})
.catch(err=>{
console.log("push err:", err);
})
}
![y***@sina.com](https://img-cdn-tc.dcloud.net.cn/account/identicon/00de8d5efefbe3279a218b9f1bb78dd6.png)
- 发布:2023-12-08 11:02
- 更新:2023-12-15 19:35
- 阅读:232
产品分类: uniapp/H5
PC开发环境操作系统: Windows
PC开发环境操作系统版本号: 22h2
HBuilderX类型: 正式
HBuilderX版本号: 3.98
浏览器平台: Chrome
浏览器版本: 119.0.6045.200
项目创建方式: HBuilderX
示例代码:
操作步骤:
for(xxxxxx){
let pushSend = {
"user_id": xxxxx,
"title": title,
"content": content,
"payload": {
"oids":xxx
}
}
uniPush.sendMessage(pushSend)
.then(res=>{
console.log("push res:", res);
if(res.errCode){
console.log("推送失败:", res.errMsg);
}
})
.catch(err=>{
console.log("push err:", err);
})
}
for(xxxxxx){
let pushSend = {
"user_id": xxxxx,
"title": title,
"content": content,
"payload": {
"oids":xxx
}
}
uniPush.sendMessage(pushSend)
.then(res=>{
console.log("push res:", res);
if(res.errCode){
console.log("推送失败:", res.errMsg);
}
})
.catch(err=>{
console.log("push err:", err);
})
}
预期结果:
不同用户都正确收到推送消息
不同用户都正确收到推送消息
实际结果:
一个用户没有收到消息,一个用户重复收到两条一样内容的消息。
一个用户没有收到消息,一个用户重复收到两条一样内容的消息。
bug描述:
for(xxxxxx){
let pushSend = {
"user_id": xxxxx,
"title": title,
"content": content,
"payload": {
"oids":xxx
}
}
uniPush.sendMessage(pushSend)
.then(res=>{
console.log("push res:", res);
if(res.errCode){
console.log("推送失败:", res.errMsg);
}
})
.catch(err=>{
console.log("push err:", err);
})
}
如代码所示,在一个for循环里面,调用unipush各推送一条内容不同的消息到两个不同的用户。结果会发生一个用户没有收到消息,一个用户重复收到两条一样内容的消息。
后尝试添加延时后,可正常发送。但时间间隔不能太小,试过100ms,两个用户会都收到消息,但是消息内容会是一样的。
let m=0
for(xxxxxx){
let pushSend = {
"user_id": xxxxx,
"title": title,
"content": content,
"payload": {
"oids":xxx
}
}
let t = 500*m
m++
setTimeout(()=>{
uniPush.sendMessage(pushSend)
.then(res=>{
console.log("push res:", res);
if(res.errCode){
console.log("推送失败:", res.errMsg);
}
})
.catch(err=>{
console.log("push err:", err);
})
}, t)
}
y***@sina.com (作者)
“每个任务需要调用一次 uniCloud.getPushManager使得每个任务拿到的是不同的实例”,这个麻烦在文档里面说明一下?
2023-12-18 10:17