How can I detect whether an iOS device is in silent mode or not?
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 switchAVAudioSessionCategoryPlayBack: Your Audio continues with the Silent
switch set to silent or when the screen locks
Detect silent mode in iOS 7
Check this thread - Detecting the iPhone's Ring / Silent / Mute switch using AVAudioPlayer not working?
And this API - SoundSwitch
How it works:
- Play an audio file of 0.5 secs, every sec (after completion..)
- Check how long it took to play the sound
- Callback called real fast? nothing was played (silent switch is ON)
Enjoy!
Related Topics
Module 'Googlemobileads' Not Found in iOS
Two Buttons Inside Hstack Taking Action of Each Other
How to Make a Grouped Barchart with iOS-Charts
Hide a Phone Call Completely in iOS (Jailbreak Device)
Nscache Emptied When App Enters Background
How to Send a Uilongpressgesture Programmatically
How to Set the Accessibility Label for a Particular Segment of a Uisegmentedcontrol
Apple Rejected App 10.6 Because Facebook Opens Safari to Login
Physicsbody Doesn't Adhere to Node's Anchor Point
Xcode:Why Launchoptions in Didfinishlaunchingwithoptions Always Nil
Change Pin Image on Mkmapview in Swift
How to Sort 1 Array in Swift/Xcode and Reorder Multiple Other Arrays by the Same Keys Changes
Read Binary Qr Code with Avfoundation
Getting the Action of Uigesturerecognizer in iOS