自定义iOS UILocalNotification声音无法播放(可能与Xcode更新有关) [英] Custom iOS UILocalNotification sound does not play (possibly related to Xcode update)

查看:308
本文介绍了自定义iOS UILocalNotification声音无法播放(可能与Xcode更新有关)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 UILocalNotification 获取自定义声音,而我根本就没有声音。如果我使用 UILocalNotificationDefaultSoundName ,我确实得到了默认声音,但是当指定了自定义声音时,没有声音,只有消息。据我所知,声音不到30秒,而且格式正确。这是文件信息的屏幕截图:

I'm trying to get a custom sound working on a UILocalNotification, and I'm just getting no sound at all. If I use UILocalNotificationDefaultSoundName, I indeed get the default sound, but when the custom sound is specified, there is no sound, just the message. The sound is less than 30 seconds and it's in the right format, as far as I can tell. Here's a screenshot of the file info:

我在XCode的 DerivedData 目录中检查过.app目录,而 alarm.caf 文件位于应用程序的根目录下,我相信这意味着它在捆绑(对吗?)。

I've inspected the .app directory in XCode's DerivedData directory, and the alarm.caf file is at the root of the app, which I believe means it's in the bundle (right?).

我很确定这是前一段时间了,我已经升级了Xcode。也许这是一个提示?

I'm pretty sure this was working a while ago, and I've since upgraded Xcode. Maybe that is a hint?

我也试过删除/重新安装/重启,如其他答案所述。正如你所看到的,我首先打电话给 cancelAllLocalNotifications

I've also tried deleting/reinstalling/rebooting as mentioned in other answers. As you can see, I'm calling cancelAllLocalNotifications first.

有谁知道可能出现什么问题?

Does anyone have any idea what could be wrong?

[[UIApplication sharedApplication] cancelAllLocalNotifications];
NSLog(@"installing alarm");
[arguments pop]; // name
[arguments pop]; // title
alarm.alertBody = [arguments pop];
alarm.fireDate = [[NSDate date] addTimeInterval:[[arguments pop] intValue]/1000];
//alarm.soundName = UILocalNotificationDefaultSoundName;
alarm.soundName = @"alarm.caf";

[[UIApplication sharedApplication] scheduleLocalNotification:alarm];


推荐答案

您的代码似乎很好。

尝试清理项目,从设备/模拟器卸载应用程序,然后重新安装。它可能有助于:))

Try to clean your project, uninstall your app from your device/simulator, then re-install it. It could help maybe :)

这篇关于自定义iOS UILocalNotification声音无法播放(可能与Xcode更新有关)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆