我在CallKit
上两次通话有问题。接听新电话时,我丢了sound/audio
。我认为问题是在调用didDeactivate
和didActivate
时出现的,因为当我手动禁用并重新激活AVAudioSession
时,我也会丢失sound/audio
。我想知道是否可以禁用didDeactivate
和didActivate
...
谢谢。
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];
}