如何在CallKit中不调用didDeactivate和didActivate

时间:2019-04-24 10:05:57

标签: swift avaudiosession callkit

我在CallKit上两次通话有问题。接听新电话时,我丢了sound/audio。我认为问题是在调用didDeactivatedidActivate时出现的,因为当我手动禁用并重新激活AVAudioSession时,我也会丢失sound/audio。我想知道是否可以禁用didDeactivatedidActivate ...

谢谢。

func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
    print("Received \(#function)")
    print("ACTIVATE")
    activateAudioSession()
}


func provider(_ provider: CXProvider, didDeactivate audioSession: AVAudioSession) {
    print("Received \(#function)")
    print("DEACTIVATE")
    deactivateAudioSession()
}


- (void) activateAudioSession {

    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *setError = nil;

    [audioPlayer play];

    [audioSession setActive: NO error: nil];
    if (![[audioSession category] isEqualToString:AVAudioSessionCategoryPlayAndRecord])
        [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error:&setError];
    if (![[audioSession mode] isEqualToString:AVAudioSessionModeVoiceChat])
        if ([AVAudioSession instancesRespondToSelector: @selector (setMode:error:)]) {
            [audioSession setMode:AVAudioSessionModeVoiceChat error:&setError];
        }

    [audioSession setActive: YES withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker|AVAudioSessionCategoryOptionAllowBluetooth error: nil];

}


- (void) deactivateAudioSession {
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    [audioPlayer stop];
    [audioSession setActive: NO error: nil];
}

0 个答案:

没有答案