uni-app unipush2.0 在线个推渠道问题

uni-app unipush2.0 在线个推渠道问题

示例代码:

exports.main = async (event, context) => {  
    try {  
        const str =  
            "{\"title\":\"青羊工业园H区(广富路北50米)\",\"content\":\"冰川时代天然矿泉水\",\"push_clientid\":[\"641a8d465b68402dff5ac323c9a8ca1b\"],\"sound\":\"pushsound\"}"  
        const params = JSON.parse(str)  
        const result = await uniPush.sendMessage({  
            ...params,  
        })  
        console.log(result)  
        return result  
    } catch (error) {  
        console.log(error)  
        return error  
    }  
};

操作步骤:

  • 云函数sendMessage如何传递Android渠道模版id

预期结果:

  • sendMessage正常传递Android渠道模版id,触发自定义铃声(在线)

实际结果:

  • 未触发自定义铃声(在线)

bug描述:

  • Dcloud后台已配置渠道,客户端已添加插件并且打包,在Dcloud开发者后台发送通知正常触发自定义铃声(iOS, Android皆可)。
  • 在uniCloud云函数中调用sendMessage发送通知,iOS正常,Android无自定义铃声。
  • 以上测试内容都是在线情况,云函数日志查询也是online推送,所以,应该是走个推渠道,未走厂商渠道。
  • 多个文档查看,并未说明sendMessage如何传递Android渠道模版id。

更多关于uni-app unipush2.0 在线个推渠道问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html

3 回复

应用在线直接前端实现铃声等

更多关于uni-app unipush2.0 在线个推渠道问题的实战教程也可以访问 https://www.itying.com/category-93-b0.html


在线的话可以这样写
uni.createPushMessage({
title: res.data.title,
content: res.data.content,
when: new Date(),
sound: ‘none’, //显示消息时的播放的提示音,可取值: “system”-表示使用系统通知提示音; “none”-表示不使用提示音; 默认值为“system”。
payload: res.data.payload,
success(mres) {
console.log(“createPushMessage:”, mres) //监听推送消息 透传消息
const innerAudioContext = uni.createInnerAudioContext();
innerAudioContext.autoplay = true;
innerAudioContext.src = ‘/static/sound/pushsound.mp3’;
}
})

根据你的描述,问题在于云函数调用unipush2.0的sendMessage接口时,Android设备未触发自定义铃声,而iOS正常。这通常是因为Android渠道参数未正确传递。

在unipush2.0中,Android渠道需要传递channel字段来指定渠道模板。修改你的代码,在params中添加channel字段:

exports.main = async (event, context) => {  
    try {  
        const str =  
            "{\"title\":\"青羊工业园H区(广富路北50米)\",\"content\":\"冰川时代天然矿泉水\",\"push_clientid\":[\"641a8d465b68402dff5ac323c9a8ca1b\"],\"sound\":\"pushsound\"}"  
        const params = JSON.parse(str)
        // 添加Android渠道配置
        params.channel = {
            "android": {
                "channel_id": "your_channel_template_id"  // 替换为你在DCloud后台配置的渠道模板ID
            }
        }
        const result = await uniPush.sendMessage({  
            ...params,  
        })  
        console.log(result)  
        return result  
    } catch (error) {  
        console.log(error)  
        return error  
    }  
};
回到顶部