我使用的是react-native-push-notification npm包。在创建通知通道时,我设置了自定义声音的路径,如下所示:
PushNotification.createChannel(
{
channelId: 1, // (required)
channelName: 'My Channel', // (required)
channelDescription: 'A channel to categorise your notifications', // (optional) default: undefined.
soundName: 'tone1',
playSound: true,
importance: 4,
vibrate: true,
},
(created) => console.log(`createChannel returned '${created}'`),
);对于ios,我将声音添加到XCode的项目根文件夹中,如下所示:


但这不起作用,并且仍然播放默认声音。在Android上,自定义声音工作正常。我甚至导入了声音文件并手动播放,以确保它正常工作:
import SoundPlayer from 'react-native-sound-player';
SoundPlayer.playSoundFile('tone1', 'mp3');我甚至在soundName变量中使用了扩展.mp3,但它仍然不起作用。
库版本: 7.3.2
发布于 2021-09-28 06:39:09
我能让它正常工作。结果发现我没有将声音文件添加到正确的文件夹中。我们必须将其添加到ios/目录中(与Pods文件夹的级别相同)。
此外,当我们计划本地通知时,我还必须传递soundName变量。以前,我只在创建通道时传递变量。
PushNotification.localNotificationSchedule({
title: 'Hello',
message: 'Check Notification' + new Date(Date.now() + 1 * 1000),
date: new Date(Date.now() + 1 * 1000), // in 1 secs
allowWhileIdle: false, // (optional) set notification to work while on doze, default: false
channelId: 'checkNotification',
soundName: 'tone5.mp3', // (optional) Sound to play
});https://stackoverflow.com/questions/69345944
复制相似问题