我正在从Web下载声音文件,并且我得到的路径在这里/var/mobile/Containers/Data/Application/9A3E2F61-AD0F-42B1-9BDA-81922E630AB6/Library/NoCloud/My_App/SoundTunes/My_Tune.wav
现在,尽管我的持续时间my_tune
短于default tune
,但我正在尽一切努力设置my_tune
进行通知,但每次响起25 seconds
时都会发出通知{p
帮我如何设置my_tune
到本地通知环的路径
NSURL *urlTuneTime = [[NSFileManager.defaultManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] lastObject];
NSURL *urlTuneTimeok = [urlTuneTime URLByAppendingPathComponent:@"NoCloud/My_App/SoundTunes/"];
NSURL *urlTuneTimeokk = [urlTuneTimeok URLByAppendingPathComponent:getTuneTime];
NSLog(@"here is the overall got path of time tune%@", urlTuneTimeokk);
content.sound = [UNNotificationSound soundNamed: @"../SoundTunes/My_Tune.wav" ];
//content.sound = [UNNotificationSound soundNamed: @"NoCloud/MyApp/SoundTunes/My_Tune.wav" ];
答案 0 :(得分:0)
根据soundNamed initializer上的UNNotificationSound
文档:
此文件必须位于当前可执行文件的主捆绑包中或当前应用容器目录的Library / Sounds目录中。
因此,您必须使用URL将下载的文件保存到应用程序的Library/Sounds
目录中:
// save your file here
NSURL *soundsDirectoryUrl = [[[NSFileManager.defaultManager URLsForDirectory:NSLibraryDirectory inDomains:NSUserDomainMask] firstObject] URLByAppendingPathComponent:@"Sounds"];
NSURL *fileUrl = [soundsDirectoryUrl URLByAppendingPathComponent:@"fileName.wav"];
// create UNNotificationSound
content.sound = [UNNotificationSound soundNamed: "fileName.wav" ];