显示 UIAlertView 时播放本地通知默认声音? [英] Play local notification default sound when displaying UIAlertView?

查看:18
本文介绍了显示 UIAlertView 时播放本地通知默认声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'm writing a reminders app for iPhone that displays reminders using local notifications.

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

If a reminder goes off while the application is running, the local notification isn't displayed. Instead, the didReceiveLocalNotification method is called in my app delegate, and I mimic the local notification dialog by displaying a UIAlertView with the reminder text.

当本地通知显示在应用外时,设备会振动并发出UILocalNotificationDefaultSoundName 已播放.同样,当显示 UIAlertView 时,我想在应用程序中模仿这一点.

When local notifications are displayed outside of the app, the device vibrates and the sound specified by UILocalNotificationDefaultSoundName is played. Again, I'd like to mimic this in the app when displaying the UIAlertView.

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

I can vibrate the device by calling AudioServicesPlaySystemSound(kSystemSoundID_Vibrate), but I can't figure out how to play the local notification default sound. There's no equivalent SystemSoundID constant, and I'm not sure what the path would be.

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

tl;dr I'd like to play the local notification default sound when displaying a UIAlertView. Any ideas?

推荐答案

好问题.理想情况下,会有一种使用 AudioServices 选择系统声音的方法.但是,Apple 的系统声音服务参考"中的以下声明表明并非如此:

Good question. Ideally, there would be a way of selecting a system sound using AudioServices. However, the following statement from Apple's "System Sound Services Reference" suggests otherwise:

在 Mac OS X 中,当用户有将系统偏好配置为闪存警报屏幕或声音无法呈现,调用此函数将导致屏幕闪烁.在 Mac OS X 中,通过持续的kSystemSoundID_UserPreferredAlert 到播放由系统偏好设置中的用户.在iOS中没有首选的用户警报声音.

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

Since it seems like the SDK has little to offer, you might wish to mimick the system sounds by using your own wav file. There is a nice library at the following link, perhaps it will have the sound you're looking for: http://sites.google.com/site/iphonesounds/iPhoneOriginalSystemSounds_WAV.zip

祝你好运!

这篇关于显示 UIAlertView 时播放本地通知默认声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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