Callkit uses a Bluetooth headset as an audio output

I am working on VOIP with Callkit
It works great except for the audio source
It always outputs sound using the iPhone speaker

some of them will answer that the specified set is AvAudioSession Option , since AVAudioSessionCategoryOptionAllowBluetooth will work, but still failed
and I tried to set the bluetooth headset as preferred, like this , failed

By the way, how to make a ringtone for broadcast using a headset?
below is my code, follow the suggestion in this discussion , I configure AVAudioSession right after dialing and get an incoming call

 - (void)getCall:(NSDictionary *)infoDic { CXCallUpdate *update = [[CXCallUpdate alloc]init]; // config update NSUUID *uuid = [NSUUID UUID]; [self.provider reportNewIncomingCallWithUUID:uuid update:update completion:^(NSError * _Nullable error) { if (error) NSLog(@"%@", error.localizedDescription); }]; NSArray *video = @[@(ReceiveVideoReq), @(VideoCalling)]; if ([video containsObject:@(self.client.callStage)]) [ProviderManager configureAudio:true]; else [ProviderManager configureAudio:false]; } - (void)dialPhone:(BOOL)isVideo { CXHandle *handle = [[CXHandle alloc]initWithType:CXHandleTypePhoneNumber value:@"AAAA"]; CXStartCallAction *start = [[CXStartCallAction alloc]initWithCallUUID:uuid handle:handle]; start.video = isVideo; CXTransaction *trans = [[CXTransaction alloc]initWithAction:start]; [self callControlReq:trans]; [ProviderManager configureAudio:isVideo]; } + (void)configureAudio:(BOOL)isVideo { NSError *error=nil, *sessionError = nil; AVAudioSession *sess = [AVAudioSession sharedInstance]; [sess setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth | AVAudioSessionCategoryOptionAllowBluetoothA2DP error:&sessionError]; if (sessionError) NSLog(@"ERROR: setCategory %@", [sessionError localizedDescription]); if (isVideo) [sess setMode:@"AVAudioSessionModeVideoChat" error:&sessionError]; else [sess setMode:@"AVAudioSessionModeVoiceChat" error:&sessionError]; if (sessionError) { NSLog(@"ERROR: setCategory %@", [sessionError localizedDescription]); } [sess overrideOutputAudioPort:AVAudioSessionPortOverrideNone error:&sessionError]; [[AVAudioSession sharedInstance] setActive:true withOptions:AVAudioSessionSetActiveOptionNotifyOthersOnDeactivation error:&error]; [[UIApplication sharedApplication] beginReceivingRemoteControlEvents]; } 
+5
source share

Source: https://habr.com/ru/post/1269597/


All Articles