Expo Notifications自定义通知铃声不生效且频道配置异常问题求助
Expo Notifications自定义通知铃声不生效且频道配置异常问题求助
我正在开发一个番茄钟App,想在时间结束时发送本地App内通知,并且希望使用自定义音频(后续还要支持用户自定义铃声)。但不管怎么配置,通知始终只播放手机默认的提示音,甚至连我设置的通知频道配置都没生效,实在搞不懂哪里出问题了🥲
我的实现代码
下面是处理通知的核心函数,我先创建了自定义通知频道,然后调度5秒后触发的测试通知:
const handlePlayPress = async () => { await Notifications.setNotificationChannelAsync("customato", { importance: Notifications.AndroidImportance.HIGH, name: "Customato", sound: "clocktower.wav", lockscreenVisibility: Notifications.AndroidNotificationVisibility.PUBLIC, vibrationPattern: [30, 250, 250, 250], enableVibrate: true, lightColor: "#FF231F7C" }).then(value => console.log(value)) console.log("testing notif") console.log(await Notifications.getNotificationChannelAsync("customato")) await Notifications.scheduleNotificationAsync({ content: { title: "Testing pomodoro", body: "Time's up!", sound: "clocktower.wav" }, trigger: { type: Notifications.SchedulableTriggerInputTypes.TIME_INTERVAL, seconds: 5, channelId: "customato" } }) }
app.json配置
我已经在app.json里配置了expo-notifications的sound路径:
[ "expo-notifications", { "color": "#ffffff", "sounds": ["./assets/audio/clocktower.wav", "./assets/audio/beep.mp3"] } ]
文件目录结构
音频文件的存放路径是这样的:
项目根目录 ├── assets │ └── audio │ ├── clocktower.wav │ └── beep.mp3 ...
调试中发现的异常
触发通知后,我打印了创建后的通知频道信息,发现配置完全没生效:
{ "audioAttributes": null, "bypassDnd": false, "description": null, "enableLights": false, "enableVibrate": true, "groupId": null, "id": "customato", "importance": 6, "lightColor": "#00000000", "lockscreenVisibility": 0, "name": "Customato", "showBadge": true, "sound": "default", "vibrationPattern": [0, 250, 250, 250] }
对比我设置的参数,明显有问题:
sound被重置成了"default"lightColor变成了透明色(我设置的是#FF231F7C)vibrationPattern的第一个值从30变成了0lockscreenVisibility也未应用我设置的PUBLIC属性
已经尝试过的排查操作
- 反复确认
channelId没有拼写错误,完全匹配 - 添加音频文件后已经重新build了App
- 检查过音频文件是wav格式,符合Expo对通知音频的格式要求
有没有大佬遇到过类似的问题?或者能帮我看看哪里配置遗漏了吗?感激不尽🙏




