如何使用fileURLRef检索UILocalNotificationDefaultSoundName

时间:2014-04-08 07:47:46

标签: ios uialertview core-audio uilocalnotification nsurl

我想从

播放UILocalNotificationDefaultSoundName
alert.soundName = UILocalNotificationDefaultSoundName;

with:

 NSURL *soundFileURLRef  =  [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"fileName" ofType:@"wav"]];
 OSStatus  oStatus = AudioServicesCreateSystemSoundID ((__bridge CFURLRef)soundFileURLRef, &aSoundID);
if (oStatus == kAudioServicesNoError)
                    AudioServicesPlaySystemSound (aSoundID);

有没有办法可以获得UILocalNotificationDefaultSoundName的名称和类型?

1 个答案:

答案 0 :(得分:0)

不幸的是,您的应用无法使用系统声音。来自文档:

注意:iOS应用程序无法使用系统提供的警报声和系统提供的用户界面声音效果。例如,使用kSystemSoundID_UserPreferredAlert常量作为AudioServicesPlayAlertSound函数的参数将不会播放任何内容。

更新

虽然Apple确实说你无法访问系统声音,但我认为它们必须意味着你不能出于自己的目的访问它们,但我看到UILocalNotification.h提供了:

UIKIT_EXTERN NSString *const UILocalNotificationDefaultSoundName;

“标识显示通知警报时要播放的默认系统声音。将此值分配给soundName属性。”我现在在我的应用程序中使用它,它似乎工作正常。