如何为UILocalNotification添加声音? [英] How to add sound for UILocalNotification?

查看:105
本文介绍了如何为UILocalNotification添加声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为我的应用程序完成了基本通知。我想为我的通知添加声音效果。

I have done with basic notification for my App. I want to add sound effect to my notification.

UILocalNotification *localNotification = [[UILocalNotification alloc] init];
if (localNotification == nil)
    return;

localNotification.fireDate = [NSDate date];
//localNotification.timeZone = [NSTimeZone defaultTimeZone];
localNotification.alertBody = msg;
localNotification.soundName = @"Morse.aiff";

[[UIApplication sharedApplication] presentLocalNotificationNow:localNotification];

如何添加音效?

推荐答案

您可能需要先阅读准备自定义警报声音(确保您的自定义声音短于30秒)。

You may want to start with reading Preparing Custom Alert Sounds of the Local and Push Notification Programming Guide (make sure that your custom sound is shorter than 30s).

如果你想使用默认声音:使用 UILocalNotificationDefaultSoundName (按照Euroboy的建议)

If you want to use the default sound: use UILocalNotificationDefaultSoundName (as suggested by Euroboy)

更新:您似乎并不是唯一遇到此问题的人。 这里描述了一种可能的(但当然不是很好的)解决方案。 a>。

Update: You seem to be not the only person experiencing this problem. A possible (but of course not a good) solution is described here.

这篇关于如何为UILocalNotification添加声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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