UILocalNotification 自定义声音

发布于 2024-10-02 05:39:00 字数 770 浏览 7 评论 0原文

我已经寻找解决方案几个小时了..运气绝对为零。

我设置了一个本地通知:

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.txt”。资源文件夹中的“caf”文件。

为什么不播放我的声音????

谢谢。

I have been searching for a solution for hours.. with absolutely zero luck.

I set up a Local Notification:

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

Notice the sound name...

I tried to put 10 sounds (aiff, wav, caf...etc), but the notification just pops up with the default sound :/

I have the "fireburn.caf" file in the Resources folder.

Why is it not playing my sound?????

Thanks.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

水中月 2024-10-09 05:39:00

解答:

代码没有问题。

只是愚蠢的 iPhone 没有取消我用默认声音发出的旧通知 -_-;

当我清理项目时,从手机中删除了应用程序并重新启动手机,然后它就工作了。

希望有人觉得这有帮助。

ANSWER:

Nothing wrong with the code..

It's just that the stupid iPhone didn't cancel the old notifications that I made with the default sound -_-;

When I cleaned the project, deleted the app from the phone AND REBOOTED the phone THEN it worked..

Hope someone finds this helpful.

來不及說愛妳 2024-10-09 05:39:00

您正在使用 清理旧通知吗

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

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

are you cleaning the old notifications with

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

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

?

Oo萌小芽oO 2024-10-09 05:39:00

试试这个:

notif.soundName = [strSoundFileName copy];

Try this:

notif.soundName = [strSoundFileName copy];
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文