UILocalNotification播放应用文档中的声音
我知道soundName
只支持应用程序包中的soundName
,但我看到程序在通知中播放录制的声音,即使程序已关闭。 怎么实现呢? 任何想法对我来说都很重要..
将NSURL
获取到应用程序文档目录的一种可靠方法就是这样……
NSURL *documentsDirectoryURL = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject];
然后你就可以像这样得到你的声音文件的NSURL
参考…
NSURL *soundURL = [documentsDirectoryURL URLByAppendingPathComponent:@"sound.caf"];
如果您需要该URL的资源路径的字符串表示,您可以像这样获取它…
NSString *pathRepresentation = [soundURL absoluteString];
我检查了ios 5.0.1上的下一个方法工作:
只需设置这样的相对路径
notify.soundName = @"../Documents/blabla.caf"