You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter Awesome Notifications iOS自定义通知声音无法播放问题排查

iOS端自定义通知声音无法播放的排查与解决

针对你使用Awesome Notifications包时遇到的iOS自定义通知声音失效问题,按以下步骤逐一排查修复:

1. 修正跨平台soundSource配置

不要直接写死soundSource,需根据平台区分配置,确保两端路径格式正确:

NotificationChannel(
  channelKey: notif.notificationIdIlacZamani_key(),
  channelName: notif.notificationIdIlacZamani_kanal_adi(),
  channelDescription: notif.notificationIdIlacZamani_kanal_aciklama(),
  playSound: true,
  soundSource: Platform.isAndroid ? 'resource://raw/tunnel' : 'tunnel.caf',
  onlyAlertOnce: true,
  groupAlertBehavior: GroupAlertBehavior.Children,
  importance: NotificationImportance.Max,
  defaultPrivacy: NotificationPrivacy.Public,
  defaultColor: Colors.deepPurple,
  ledColor: Colors.deepPurple,
)

注意:iOS端直接写文件名即可,但要保证文件名、大小写与实际文件完全匹配(iOS文件系统区分大小写)。

2. 确认文件已加入Copy Bundle Resources

这是iOS端能读取到声音文件的核心前提:

  • 打开iOS项目的ios/Runner.xcworkspace文件
  • 左侧选中Runner项目,切换到Build Phases标签页
  • 找到Copy Bundle Resources列表,检查tunnel.caf是否在其中
  • 若不在,点击列表下方的+按钮,手动选中tunnel.caf添加进去

3. 验证声音文件合规性

iOS对通知声音有严格限制,不符合要求会自动切换为默认声音:

  • 音频编码必须为PCM或IMA4(.caf是容器格式,需确保内部编码正确,可通过afconvert工具转换:afconvert -f caff -d ima4 input.wav tunnel.caf)
  • 文件时长不能超过30秒,超过则iOS会忽略自定义声音
  • 建议采样率44.1kHz、位深16位,单声道/立体声均可

4. 重置通知通道

iOS的通知分类(对应Awesome Notifications的Channel)一旦创建就无法修改,若之前创建过不带自定义声音的通道,需:

  • 完全卸载app
  • 重启测试设备
  • 重新安装app并测试

5. 检查设备与权限

  • 确保测试设备未开启静音模式,通知音量已调至正常
  • 确认app已获得完整通知权限(包括声音权限),可在iOS「设置」→你的app→「通知」中查看验证

完成以上步骤后,iOS端的自定义通知声音即可正常播放。

内容的提问来源于stack exchange,提问作者kksal55

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.25 03:57:47