UILocalNotification 声音未在设备上播放

发布于 2024-11-28 17:07:48 字数 682 浏览 2 评论 0原文

我被同样的问题困扰了一段时间,希望有人能提供帮助。

我创建了一个闹钟应用程序,它使用 UILocalNotification 在选定的时间播放闹钟声音。

我的应用程序在模拟器上运行良好,但当我开始在 iPhone 上测试它时,通知声音停止响起。

我的声音在 .caf 中,大约 20 秒长,大小写正确,一切都正确,所以我真的不明白为什么它不响。我在应用程序的其他地方使用相同的声音文件,它工作正常,所以我知道文件已正确加载。 通知正常显示,只是没有声音。是的,我确保 iPhone 的音量已调高。

有谁知道为什么会发生这种情况? 下面是我的代码。

先感谢您! -艾玛

UILocalNotification* alarm = [[ULocalNotification alloc] init];
alarm.fireDate = pickedDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.hasAction = YES;
alarm.alertAction = @"SNOOZE";
alarm.repeatInterval = 0;
alarm.soundName =  @"Alarm11.caf";
alarm.alertBody = @"Alarm";    
[app scheduleLocalNotification:alarm];

I have been stuck on the same problem for a while, and I hope someone can help.

I created an alarm clock app, which uses UILocalNotification to play an alarm sound at the selected time.

My app was working fine on the simulator, but when I started testing it on an iPhone, the notification sound stopped ringing.

I have the sound in .caf, about 20 seconds long, correct capitalization and everything, so I really can't figure out why it doesn't ring. I use the same sound file elsewhere in the app, and it works fine, so I do know the file is loaded properly.
The notification shows up properly, just without the sound. And yes, I made sure the volume is turned up on my iPhone.

Does anyone have any idea why this is happening?
Below is my code.

Thank you in advance! -Ema

UILocalNotification* alarm = [[ULocalNotification alloc] init];
alarm.fireDate = pickedDate;
alarm.timeZone = [NSTimeZone defaultTimeZone];
alarm.hasAction = YES;
alarm.alertAction = @"SNOOZE";
alarm.repeatInterval = 0;
alarm.soundName =  @"Alarm11.caf";
alarm.alertBody = @"Alarm";    
[app scheduleLocalNotification:alarm];

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

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

发布评论

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

评论(2

为人所爱 2024-12-05 17:07:48

我遇到了同样的问题,并在 Stackoverflow 上的类似问题中找到了解决方案(但我无法再次找到它以提供链接) - 我的问题的解决方案是打开我的 mac 的系统偏好设置并打开声音选项。在“声音”屏幕中,取消选中“播放用户界面声音效果”,然后重新选中以重新设置,然后您的声音应该可以正常播放。

I had the same problem and found a solution in a similar question on Stackoverflow (but I can't find it again to provide the link) - The solution to my problem was to open the System Preferences for my mac and open the Sounds option. In the Sounds screen, uncheck and then re-check the 'Play user interface sound effects' to re-set and your sound should then play ok.

倾城°AllureLove 2024-12-05 17:07:48

我有类似的问题。确保在文件检查器选项卡中检查了目标成员资格。另外,从手机中删除该应用程序,进行全新构建,然后重新启动手机并查看其是否有效。

I had a similar issue. Make sure the target membership is checked in the file inspector tab. Also, remove the app from your phone, do a clean build and then, restart your phone and see if it works.

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