问题
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