How can I determine if an iOS device is in silent mode or not?

I was looking for a watch, and I can not find any API that explains how to determine if the iPhone call is in silent mode or not. This is what I am talking about:

iPhone Ringer Switch

Anyway, can I find out if the silent mode of the iOS device is turned on using Swift code? I am specifically looking for iOS8 and since iOS5 are deprecated. Thanks.

+6
source share
1 answer

I don’t think there is, and you probably don’t need to access the API directly to determine if the device is disconnected or not. What you need to know is:

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 {AVAudioSessionCategory} you can specify:

AVAudioSessionCategorySoloAmient: your sound is muted by screen lock and using the Silent switch

AVAudioSessionCategoryPlayBack: your audio continues using the Silent switch turned off or when the screen is locked

+6
source

All Articles