我正在尝试在我的应用程序中应用计划通知,它运行良好但没有声音,所以我在两件事上需要帮助
1(如何播放声音并用我自己的mp3制作我想玩?
2(如果我有几次如何修改代码每次发送本地通知?
const times = ['1:15 AM', '3:15 PM', '6:00 PM', '8:25 PM', '11:45 PM'];
const localNotification = {
title : 'Testing',
body : 'The body ',
data: { name : 'This is the data'},
ios : {
sound : true,
_displayInForeground : true
},
ChannelAndroid : {
name : 'Sound',
sound : true,
vibrate : [ 0, 250, 250, 250 ]
}
}
const schedulingOptions = {
time : (new Date()).getTime() + 5000,
}
const currentTime = `${new Date().getHours()}:${new Date().getMinutes()}`;
console.log(currentTime);
const pushTime = '1:52';
if (currentTime === pushTime) {
Notifications.scheduleLocalNotificationAsync(localNotification, schedulingOptions);
}
你可以简单地使用一个名为"react-native-notification-sounds"的包来做到这一点。请浏览链接并按照说明进行操作。
https://github.com/saadqbal/react-native-notification-sounds/blob/master/README.md
import NotificationSounds, { playSampleSound } from 'react-native-notification-sounds';
NotificationSounds.getNotifications().then(SoundsList => {
console.warn('SOUNDS', JSON.stringify(SoundsList));
playSampleSound(SoundsList[1]);
});