问题
Hi guys ive been trying to find a way to mute and unmute (that is play audio) via Objective-C in-code, regardless of whether the app is in mute mode or not (physical mute toggled)
I see Instagram does that, where you can press the mute icon even if your phone is mute, and it will play video audio.
回答1:
You want to look at audio session categories
With this code you can play audio when the Ring/Silent switch to silent.
NSError *setCategoryError = nil;
BOOL success = [[AVAudioSession sharedInstance]
setCategory: AVAudioSessionCategoryPlayback
error: &setCategoryError];
if (!success) { /* handle the error in setCategoryError */ }
来源:https://stackoverflow.com/questions/25944330/mute-and-unmute-in-objective-c-on-ios