w***@163.com
w***@163.com
  • 发布:2026-02-10 14:38
  • 更新:2026-02-10 14:38
  • 阅读:62

DCloud-PushSound插件 推送后没有自定义铃声

分类:ASK社区

客户端
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",

2026-02-10 14:38 负责人:无 分享
已邀请:
Ask小助手

Ask小助手 - Ask社区AI助手

根据知识库内容,DCloud-PushSound插件自定义铃声不生效的问题主要涉及以下关键点:

  1. 文件放置位置
    自定义铃声文件需放在 nativeResources/android/res/raw/ 目录下(打包后生效),文件名需与代码中 soundName 完全一致(不带后缀)。例如 pushsoundhw.mp3 应命名为 pushsoundhw

  2. 客户端配置验证
    检查 setCustomPushChannelsoundName 参数是否匹配文件名(如 "pushsoundhw"),且 channelId 需与华为推送后台创建的通道ID一致。

  3. 服务端参数修正
    华为推送需通过 options.HW 配置:

    • "/message/android/notification/sound" 应直接填写文件名(如 "pushsoundhw"),无需路径或后缀。
    • "/message/android/notification/channel_id" 必须与客户端的 channelId 一致(如 "alarm_sound")。
    • 其他冗余参数(如 "channelId""sound")可移除,避免冲突。
  4. 平台差异

    • Android 8+ 必须依赖通知通道(channel),需确保华为开发者后台已创建对应通道。
    • iOS 需将铃声文件(如 .caf 格式)放入 nativeResources/ios/ 目录,并通过 "sound" 参数直接指定文件名。
  5. 调试建议

    • 确认打包后生效(自定义资源需重新打包)。
    • 检查华为推送后台的通道配置是否与代码一致。
    • 使用真机测试,模拟器可能无法触发厂商通道。

若仍无效,建议通过 DCloud插件市场 确认插件版本兼容性,或查阅华为推送官方文档验证参数格式。

内容为 AI 生成,仅供参考

要回复问题请先登录注册