在运行 iOS4 的 3G iPhone 上设置本地通知的声音 [英] Setting sounds for local notifications on a 3G iPhone running iOS4

查看:29
本文介绍了在运行 iOS4 的 3G iPhone 上设置本地通知的声音的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

在模拟器中一切正常,但是当我在运行 iOS4 的受信任的旧 iPhone 3G 上测试时,我收到通知,但只有默认声音.

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?

谢谢

推荐答案

UILocalNotification 不支持 mp3.它只支持参考页面上提到的格式和容器.

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

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

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

您可以将音频数据打包成一个aiff、wav 或 caf 文件.

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

这篇关于在运行 iOS4 的 3G iPhone 上设置本地通知的声音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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