UILocalNotification play sound from app documents

孤人 提交于 2019-12-21 16:56:02

问题


I know that UILocalNotification supports soundName only from app bundle, but I saw program that plays my recorded sound in Notification, even if program is closed. How to implement it? Any ideas is very important for me..


回答1:


A surefire way to get an NSURL to the application documents directory is like this...

NSURL *documentsDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];

Then you can get an NSURL reference to your sound file like this...

NSURL *soundURL = [documentsDirectoryURL URLByAppendingPathComponent:@"sound.caf"];

If you need a string representation of the path to the resource at that URL you can obtain it like this...

NSString *pathRepresentation = [soundURL absoluteString];



回答2:


I checked next method work on ios 5.0.1:

just setup relative path like this

notify.soundName = @"../Documents/blabla.caf"


来源:https://stackoverflow.com/questions/7904249/uilocalnotification-play-sound-from-app-documents

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!