2010-11-15 78 views
8

我一直在寻找一个解决方案的小时..绝对没有运气。UILocalNotification自定义声音

我成立了一个本地通知:

UILocalNotification *notif = [[cls alloc] init]; 

[dateComp setDay:j+1]; 
[dateComp setHour:[[time objectAtIndex:0] integerValue]+offset]; 
[dateComp setMinute:[[time objectAtIndex:1] integerValue]]; 

NSLog(@"Year: %i, Month: %i, Day: %i, Time:%i:%i\n",[dateComp year], [dateComp month], 
        [dateComp day], [dateComp hour], [dateComp minute]); 

notif.fireDate = [gregorian dateFromComponents:dateComp]; 
notif.timeZone = [NSTimeZone defaultTimeZone]; 

notif.alertBody = [names objectAtIndex: k]; 
notif.soundName = @"fireburn.caf"; 

通知声音名称...

我试图把10周的声音(AIFF,WAV,CAF ...等),但通知只是会弹出默认的声音:/

我在资源文件夹中的“fireburn.caf”文件。

为什么不打我的声音?????

谢谢。

回答

10

答:

没有错代码..

这只是愚蠢的iPhone并没有取消,我用默认的声音把旧的通知 - _ - ;

当我清理的项目,从手机中删除该应用程序并重新启动手机,然后它的工作..

希望有人认为这很有帮助。

+3

如果有人仍然应该有这个问题挣扎,我发现它可能需要做的一两件事。将音频文件拖放到项目中时,除了选中“复制...”之外,还可能需要选中“添加到目标”选项。该做的事情对我来说。无论如何感谢您的答案。 – 2012-06-16 16:22:58

+0

真棒,但是再次,你的问题必须与你添加的任何资源文件(图像,声音,字体等); – Mazyod 2012-06-17 14:49:58

1

你清理旧的通知与

UIApplication* app = [UIApplication sharedApplication]; 
NSArray* oldNotifications = [app scheduledLocalNotifications]; 

// Clear out the old notification before scheduling a new one. 
[app cancelAllLocalNotifications]; 

+0

是的..我是。没有解决。 – Mazyod 2011-11-11 22:42:52

0

试试这个:

notif.soundName = [strSoundFileName copy]; 
+1

他已经解决了这个问题! – Hemang 2012-10-03 09:55:03