我有一个使用Firebase Messaging发送通知的应用,并且我在xcode项目资源中添加了一组声音,可以在设备上播放。
我将这样的通知从我的服务器发送给订阅了特定主题的用户:
Pattern pp = Pattern.compile("[$,=?@#'^<>.()%!]");
现在,当收到通知时,声音“ alert.wav” 在设备上可以正常播放。
我想做的是在我的应用程序内部: 我想允许用户从不同的声音集中更改通知声音。
示例:播放设置1或设置2的声音的选项,我会将它们作为具有相同文件名的单独文件夹放在我的应用中。
在iOS中这可能吗?以及如何在本机反应中实现它?
答案 0 :(得分:0)
我能够做到,这就是方法:
1。在我的应用程序资源中以xcode添加了声音文件。
刚刚向包含我所有声音的文件夹添加了一个链接,但没有链接每个文件,因为我希望应用程序稍后从以下位置播放声音:“
/Library/Sounds
目录”。
2。使用rn-fetch-blob复制声音并替换声音。
通过使用 rn-fetch-blob ,我能够创建/Library/Sounds
目录,然后将声音从MainBundleDir
移到{{ 1}},该应用将在收到通知时在其中寻找声音。
我创建了一个界面,允许用户替换这些声音。
/Library/Sounds
现在,如果应用收到//Function: setup sounds
setupSounds(){
//sounds directory
const dirs = RNFetchBlob.fs.dirs
const soundsDir = dirs.CacheDir.replace('Caches','Sounds')
//Check if has sounds directory
RNFetchBlob.fs.isDir(soundsDir).then((isDir) => {
//create directory
if(!isDir) RNFetchBlob.fs.mkdir(soundsDir)
})
//Add the sound file to /Library/Sounds
RNFetchBlob.fs.writeFile(soundsDir+'/default.wav', dirs.MainBundleDir + '/sounds/jingle.wav', 'uri');
}
的通知,则该应用将播放sound: 'default.wav'
的副本default.wav
。