在运行 iOS4 的 3G iPhone 上设置本地通知声音

发布于 2024-09-24 00:35:16 字数 785 浏览 0 评论 0原文

我已使用以下代码在我的应用程序中成功安排了本地通知:

Class cls = NSClassFromString(@"UILocalNotification");

    if (cls != nil) {

        UILocalNotification *notification = [[cls alloc] init];
        notification.fireDate = self.alarmNotificationDate;
        notification.timeZone = [NSTimeZone defaultTimeZone];

        notification.alertBody = @"Alarm is due";
        notification.alertAction = @"Show Alarm";

        notification.soundName = @"alarm.mp3";

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];

其中 self.alarmNotificationDate 是另一种方法中的 NSDate 分配。

在模拟器中一切正常,但当我在运行 iOS4 的值得信赖的旧 iPhone 3G 上进行测试时,我收到了通知,但仅使用默认声音。

我尝试过不同的声音文件,但没有成功。

任何线索为什么会这样以及如何纠正它?

谢谢

I have successfully scheduled local notifications in my app using the code below:

Class cls = NSClassFromString(@"UILocalNotification");

    if (cls != nil) {

        UILocalNotification *notification = [[cls alloc] init];
        notification.fireDate = self.alarmNotificationDate;
        notification.timeZone = [NSTimeZone defaultTimeZone];

        notification.alertBody = @"Alarm is due";
        notification.alertAction = @"Show Alarm";

        notification.soundName = @"alarm.mp3";

        [[UIApplication sharedApplication] scheduleLocalNotification:notification];
        [notification release];

Where self.alarmNotificationDate is a NSDate assign in another method.

All works fine in the simulator, but when I test on my trusted old iPhone 3G running iOS4 I get the notification, but only with the default sound.

I have tried with different sound files but no success.

Any clue why it could be like this and how to correct it?

Thanks

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

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

发布评论

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

评论(3

云朵有点甜 2024-10-01 00:35:16

UILocalNotification 不支持 mp3。它仅支持参考页上提到的格式和容器。

http://developer.apple.com/库/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

因为会播放自定义警报声音
通过 iOS 系统声音设施,他们
必须是以下音频之一
数据格式:

<前><代码> 线性 PCM
MA4(IMA/ADPCM)
µ律
法律

您可以将音频数据打包在
aiff、wav 或 caf 文件。

UILocalNotification does not support mp3. It only supports the formats and containers mentioned on the reference page.

http://developer.apple.com/library/ios/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/IPhoneOSClientImp/IPhoneOSClientImp.html

Because custom alert sounds are played
by the iOS system-sound facility, they
must be in one of the following audio
data formats:

  Linear PCM
  MA4 (IMA/ADPCM)
  µLaw
  aLaw

You can package the audio data in an
aiff, wav, or caf file.

哆兒滾 2024-10-01 00:35:16

可能有几个原因:

  1. 您的声音文件是否包含在您的捆绑包中? (最有可能的是,因为它在模拟器上工作)
  2. Apple 文档说不要使用压缩音频格式。请参阅链接 此处。原因是 iPhone 硬件一次只能播放一个压缩音频文件,因此不建议将一个压缩音频文件也用于闹钟,以防用户已经在听 iTunes 中的一首歌曲。

There could be a couple of reasons:

  1. Is your sound file included in your bundle? (most likely, seeing as it works on the simulator)
  2. The Apple documentation says to not use compressed audio formats. See the link here. The reason for this being that the iPhone hardware can only play one compressed audio file at a time, and so it is not recommended to use one for the alarm as well, in case the user is already listening to a song from iTunes.
三生殊途 2024-10-01 00:35:16

您是否在文件名和文件名中使用相同的大写/小写编码来拼写声音名称?

Did you spell the name of the sound using the same upper/lower case encoding in both the file name and the filename?

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