问题描述
我一直在寻找几个小时,似乎找不到任何API来解释如何检测iPhone铃声是否处于静音模式。这就是我在说的:
I've been looking for hours and I can't seem to find any API that explains how to detect whether an iPhone ringer is in silent mode or not. This is what I'm talking about:
有没有可以使用Swift代码查看iOS设备的静音模式是开启还是关闭?我专门寻找iOS8以上,因为iOS5已被弃用。谢谢。
Is there anyway I can find out whether an iOS device's silent mode is on or off using Swift code? I'm specifically looking for iOS8 and up since the iOS5 ones have been deprecated. Thanks.
推荐答案
我不认为有,您可能不需要直接调用API来检测是否设备静音或不静音您需要知道的是:
I don't think there is and you probably don't need to directly call an API to detect if the device is muted or not. What you need to know is this:
播放声音时,您将执行以下操作:
When playing a sound, you will do something like:
try AVAudioSession.sharedInstance().setCategory({AVAudioSessionCategory})
try AVAudioSession.sharedInstance().setActive(true)
audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)
audioPlayer.prepareToPlay()
audioPlayer.play()
在{AVAudioSessionCategory },您可以指定:
In the {AVAudioSessionCategory}, you can specify:
AVAudioSessionCategoryPlayBack:您的音频继续静音
开关设置为静音或屏幕锁定
AVAudioSessionCategoryPlayBack: Your Audio continues with the Silent switch set to silent or when the screen locks
这篇关于如何检测iOS设备是否处于静音模式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!