iphone - 显示 UIAlertView 时播放本地通知默认声音?

标签 iphone cocoa-touch ios4 push-notification

我正在为 iPhone 编写一个提醒应用程序,它使用本地通知显示提醒。

如果在应用程序运行时发出提醒,则不会显示本地通知。相反,在我的应用委托(delegate)中调用 didReceiveLocalNotification 方法,并通过显示带有提醒文本的 UIAlertView 来模拟本地通知对话框。

当本地通知显示在应用程序外部时,设备会振动并发出UILocalNotificationDefaultSoundName指定的声音。玩过的。同样,我想在显示 UIAlertView 时在应用程序中模仿这一点。

我可以通过调用 AudioServicesPlaySystemSound(kSystemSoundID_Vibrate) 来振动设备,但我不知道如何播放本地通知默认声音。没有等效的 SystemSoundID 常量,我不确定路径是什么。

tl;dr 我想在显示 UIAlertView 时播放本地通知默认声音。有什么想法吗?

最佳答案

好问题。理想情况下,有一种使用音频服务选择系统声音的方法。然而,Apple 的“系统声音服务引用”中的以下声明表明了相反的情况:

In Mac OS X, when a user has configured System Preferences to flash the screen for alerts, or if sound cannot be rendered, calling this function will result in the screen flashing. In Mac OS X, pass the constant kSystemSoundID_UserPreferredAlert to play the alert sound selected by the user in System Preferences. In iOS there is no preferred user alert sound.

由于 SDK 似乎没什么可提供的,您可能希望使用自己的 wav 文件来模仿系统声音。以下链接中有一个不错的库,也许它会有您正在寻找的声音:http://sites.google.com/site/iphonesounds/iPhoneOriginalSystemSounds_WAV.zip

祝你好运!

关于iphone - 显示 UIAlertView 时播放本地通知默认声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3277811/

相关文章:

iphone - iPhone AVAudioFoundation声音完成循环

iphone - 在 Xcode 4 和 iOS 4 中定义成员和属性

ios - 带有自定义单元格(带有 .xib)的 UITableView 崩溃

html - Bootstrap 背景图像无法在 iPhone 上调整大小

objective-c - 如何构建单个 .a(Cocoa Touch 静态库)

iphone - 如何对浮点值的 NSArray 进行排序?

ios - NSTimeInterval取绝对值可以吗?

iphone - 在 iphone 3.0 上如何禁用剪切、复制和粘贴选项

ios - 从 NSMutableArray 创建字节数组

iphone - UINavigationController 不显示 Root View Controller