如何检测iOS设备是否处于静默模式?

前端之家收集整理的这篇文章主要介绍了如何检测iOS设备是否处于静默模式?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我一直在寻找几个小时,我似乎无法找到任何解释如何检测iPhone铃声是否处于静音模式的API.这就是我所说的:

无论如何我可以使用Swift代码了解iOS设备的静音模式是打开还是关闭?我特意寻找iOS8及以上,因为iOS5已被弃用.谢谢.

解决方法

我认为没有,您可能不需要直接调用API来检测设备是否静音.你需要知道的是:

播放声音时,您将执行以下操作:

try AVAudioSession.sharedInstance().setCategory({AVAudioSessionCategory})
        try AVAudioSession.sharedInstance().setActive(true)
        audioPlayer = try AVAudioPlayer(contentsOfURL: alertSound)
        audioPlayer.prepareToPlay()
        audioPlayer.play()

在{AVAudioSessionCategory}中,您可以指定:

AVAudioSessionCategorySoloAmbient: Your audio is silenced by screen
locking and by the Silent switch

AVAudioSessionCategoryPlayBack: Your Audio continues with the Silent switch set to silent or when the screen locks

原文链接:https://www.f2er.com/iOS/334306.html

猜你在找的iOS相关文章