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()
In the {AVAudioSessionCategory}
, you can specify:
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
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…