本文介绍了UILocalNotification从应用程序文档播放声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道 UILocalNotification 仅支持来自应用程序包的 soundName ,但我看到了播放我录制的声音的程序通知,即使程序关闭。如何实现呢?任何想法对我非常重要..

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..

推荐答案

一个肯定的方式得到一个 NSURL 到应用程序文档目录就是这样...

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

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

然后你可以得到一个 NSURL 您的声音文件像这样...

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

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

如果你需要一个字符串表示在那个URL的资源的路径,你可以这样获得...

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];

这篇关于UILocalNotification从应用程序文档播放声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 14:48