设置设备音量 - UILocalNotification - iphone 处于静音模式
当应用程序在后台生成 UILocalNotification 时,如何设置设备的音量(静音模式)?我正在开发警报应用程序,因此声音也必须在静音模式下播放,并且我正在使用本地通知处理应用程序警报。
严重卡在这个问题上,无法在静音模式下播放闹钟。
请帮忙..
How can i set volume of device(in silent mode) when UILocalNotification is generated when application is in background? I am working on alarm app, so sound has to be played in silent mode too and i am handling app alarm using local notification.
Badly stuck in this issue, not able to play alarm in silent mode.
Please help..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这根本不可能。
UILocalNotification
弹出窗口和声音是由另一个系统进程生成的,并且该进程观察设备静音模式,因此如果设备处于静音模式,它不会播放通知声音。如果您希望闹钟应用程序即使在设备处于静音模式时也能播放闹钟声音,则必须直接从应用程序播放闹钟声音。为此,您需要让应用程序在后台运行,然后您必须在后台播放警报声音文件。后者可以通过在 info.plist 中指定“所需背景模式”属性“音频”来完成(您必须将该属性添加到您的 plist 文件中)
现在,使用
AVAudioPlayer
,有即使设备静音时也可以通过设置音频会话类别来播放声音,如下所示:希望这会有所帮助。
It is simply not possible. The
UILocalNotification
popup and sound are generated by another system process, and that process observes the device silent mode, so it won't play the notification sound if the device is on silent.if you want your alarm clock app to play the alarm sound even when device is in silent mode, you will have to play the alarm sound right from your app. To do that, you will need to keep your app running in the background, then you will have to play the alarm sound file while in the background. The later can be done by specifying "audio" that the "Required background modes" property in your info.plist (you will have to add that property to your plist file)
Now, using
AVAudioPlayer
, there is a way to play sound even when device is silent by setting the Audio session category like this:Hope this helps.
您必须意识到,即使您的应用程序被终止,也会触发本地通知。这让我得出结论:这可能是不可能的。
但您可以这样尝试:
在激活音频会话之前。
You have to realize that local notifications are triggered even your app is killed. That leads me to conclusion that it is probably not possible to do that.
But you can try that like this:
right before you make your audio session active.