UniPush 2.0不支持自定义推送铃声,因其推送通道完全托管于DCloud服务端,sound字段仅接受预设值(如"default"、"none"),忽略自定义音频文件名;而UniPush 1.0允许调用个推REST API直接发送并由客户端插件识别sound字段播放对应资源。

UniPush 1.0 支持自定义推送铃声,2.0 不支持——这是最关键的判断。如果你的后端要自主调用 API 发送带铃声的消息,必须用 UniPush 1.0;若只走 DCloud 后台推送,2.0 虽能配铃声但无法动态控制 soundName,实际不可控。
为什么 UniPush 2.0 不能设自定义铃声
UniPush 2.0 的推送通道完全托管在 DCloud 服务端,sound 字段仅接受预设值(如 "default"、"none"),不识别自定义音频文件名。即使你在 payload 里传 sound: "alarm.mp3",服务端会直接忽略或 fallback 到系统默认音效。
而 UniPush 1.0 允许你调用个推 REST API 直接发消息,并在 android 和 ios 配置块中明确指定 sound 字段,且客户端插件能识别该字段并播放对应资源。
- UniPush 2.0 的 manifest.json 中“UniPush”配置项下没有
sound或customSound选项 - 官方文档明确标注:2.0 “仅支持通过 DCloud 后台发送”,不开放原生通道参数控制
- 实测:在 2.0 下调用
plus.push.createChannel或DCloud-PushSound.setCustomPushChannel会静默失败,无报错但铃声不生效
UniPush 1.0 下 Android 自定义铃声实操
Android 端依赖 DCloud-PushSound 插件,且必须在收到推送前完成通道注册。关键点是延迟 + 权限校验:
- 音频文件必须放在
nativeResources/android/res/raw/目录下,命名全小写、无空格、不含中文,例如notify.mp3 - 插件初始化需等 native 环境就绪,
setTimeout是必须的——过早调用setCustomPushChannel会因插件未加载而失败 -
channelId必须与推送 payload 中的android.channel_id完全一致,否则铃声不触发 - 务必检查
plus.push.hasPermission(),无权限时setCustomPushChannel无效
示例代码:
const plugin = uni.requireNativePlugin('DCloud-PushSound');
if (plus.push.hasPermission()) {
setTimeout(() => {
plugin.setCustomPushChannel({
soundName: 'notify',
channelId: 'custom_notify',
channelDesc: '订单提醒',
importance: 4,
enableVibration: true
});
}, 500);
}
iOS 自定义铃声必须走 setCustomPushChannel
iOS 不依赖插件,但要求严格:铃声文件必须是 .caf 格式、时长 ≤ 30 秒、采样率 44.1kHz、单声道,且需打包进 nativeResources/ios/ 目录。调用 setCustomPushChannel 是唯一生效方式,且必须在应用启动早期执行(比如 onLaunch)。
- 文件路径必须与
soundName参数完全匹配,例如soundName: 'alert.caf'→ 文件路径为nativeResources/ios/alert.caf - 如果铃声没响,先检查 Xcode 构建日志是否提示
Sound file not found,再确认文件是否被正确打包进 IPA - 不能用
.mp3或.wav,iOS 系统级推送只认.caf -
channelId在 iOS 上不起作用,但为兼容 Android 建议仍保持一致
示例代码:
if (plus.os.name === 'iOS') {
plus.push.setCustomPushChannel({
soundName: 'alert.caf',
channelId: 'custom_notify',
channelDesc: '订单提醒',
enableLights: true,
enableVibration: true
});
}
容易被忽略的真坑:soundName 匹配逻辑和构建路径
很多人卡在“明明文件放对了却没声音”,根本原因是构建时资源未被识别或名称大小写不一致。
-
nativeResources/android/res/raw/下的文件,在 HBuilderX 构建时不会自动校验是否存在,缺失也不会报错 - Android 的
soundName值不带扩展名(如notify对应notify.mp3),iOS 的soundName必须带.caf - uni-app 构建时,
nativeResources目录必须与uni_modules平级,且不能放在static或common下 - 修改铃声文件后,必须清除原生缓存并重新云打包——热更新不生效
验证方法:真机调试时抓取 adb logcat | grep -i sound,看到 Loaded sound: notify.mp3 才算真正加载成功。


















