AVAudioSessionPortOverrideSpeaker and avaudiosessioncategoryoptiondefadefatospeaker, avaudiosession
This article partially translates the official descriptions of these two attributes. Link:
Https://developer.apple.com/library/ios/qa/qa1754/_index.html
The origin of the problem, in iOS, when playing a sound, the need to output to the speaker. Difference between two attribute settings
The difference is that setting the AVAudioSessionPortOverride by calling overrideOutputAudioPort: is more transient than using the category option avaudiosessioncategoryoptiondefatospeaker.
The overrideOutputAudioPort method is used to set the AVAudioSessionPortOverride attribute, which is shorter than avaudiosessioncategoryoptiondefadefatospeaker.
E. g
Method 1
[Session overrideOutputAudioPort: AVAudioSessionPortOverrideSpeaker error: & error];
Method 2
[Session setCategory: avaudiosessioncategoryplayandrecordwitexceptions: avaudiosessioncategoryoptiondefadefatospeakererror: & error];
Method 1: After the settings are completed, if the headset is inserted at this time, unplug it. The playing sound is output from the receiver rather than back to the speaker.
Method 2. After setting, always output to the speaker, instead of other receivers, if there is no headset. (Simply put, if there is a Bluetooth speaker, even if there is no sound output to the Bluetooth speaker, plug in the headset, there will be sound output to the headset .)
Here is a very important part. Both attributes are used only.AVAudioSessionCategoryPlayAndRecord