客户端
export function initPushSound() {
plugin.setCustomPushChannel({
soundName: "pushsoundhw",
channelId: "alarm_sound",
channelDesc: "报警铃声",
enableLights: true,
enableVibration: true,
importance: 3,
lockscreenVisibility: 0
}, (msg) => {
console.log("push sound error :" + msg)
});
}
服务端
return await uniPush.sendMessage({
"push_clientid": jsonObj.cid, //客户端推送标识push_clientid
"force_notification": true,
"title": jsonObj.title,
"content": jsonObj.content,
"payload": jsonObj.payload,
"options": {
"HW": {
"/message/android/category": "WORK", //华为消息分类,提醒事项(如待办事项)
"/message/android/notification/channel_id": 'alarm_sound',
"/message/android/notification/default_sound": false,
"/message/android/notification/sound": "pushsoundhw",
"channelId": "huawei_channel",
"sound": "pushsoundhw",
1 个回复
Ask小助手 - Ask社区AI助手
根据知识库内容,DCloud-PushSound插件自定义铃声不生效的问题主要涉及以下关键点:
文件放置位置
自定义铃声文件需放在
nativeResources/android/res/raw/目录下(打包后生效),文件名需与代码中soundName完全一致(不带后缀)。例如pushsoundhw.mp3应命名为pushsoundhw。客户端配置验证
检查
setCustomPushChannel的soundName参数是否匹配文件名(如"pushsoundhw"),且channelId需与华为推送后台创建的通道ID一致。服务端参数修正
华为推送需通过
options.HW配置:"/message/android/notification/sound"应直接填写文件名(如"pushsoundhw"),无需路径或后缀。"/message/android/notification/channel_id"必须与客户端的channelId一致(如"alarm_sound")。"channelId"和"sound")可移除,避免冲突。平台差异
.caf格式)放入nativeResources/ios/目录,并通过"sound"参数直接指定文件名。调试建议
若仍无效,建议通过 DCloud插件市场 确认插件版本兼容性,或查阅华为推送官方文档验证参数格式。
要回复问题请先登录或注册
公告
更多>相关问题