I'm trying to simply set my audio to the iPhone earpiece. No success, this seems like it would work. Using iOS 17 on an iPhone 15 Pro. It doesn't throw any errors. Any advice appreciated.
@implementation AudioTogglePlugin
- (void)setAudioMode:(CDVInvokedUrlCommand *)command
{
NSLog(@"... audiotoggle test ...");
NSError* err;
AVAudioSession *session = [AVAudioSession sharedInstance];
[session setCategory:AVAudioSessionCategoryPlayAndRecord
mode:AVAudioSessionModeVoiceChat
options:AVAudioSessionCategoryOptionMixWithOthers
error:NULL];
[session overrideOutputAudioPort:AVAudioSessionPortOverrideNone
error:&err];
[session setActive:YES error:NULL];
NSLog(@"... audiotoggle error ... %@", err);
NSLog(@"... audiotoggle route ... %@", [session currentRoute]);
}
@end
The audio route stays on "Speaker":
inputs = ( "<AVAudioSessionPortDescription: 0x283ae0d50, type = MicrophoneBuiltIn; name = iPhone Microphone; UID = Built-In Microphone; selectedDataSource = Front>" ); outputs = ( "<AVAudioSessionPortDescription: 0x283ae0dd0, type = Speaker; name = Speaker; UID = Speaker; selectedDataSource = (null)>" )>