didActivateAudioSession 很少不被调用

didActivateAudioSession is very rarely not called

我正在开发一个支持 CallKit 的 VOIP 应用程序,有时我们的客户会遇到 didActivateAudioSession 回调从未被 iOS 系统调用的问题。

是否存在这样的已知错误,或者您是否认为我们缺少某些东西,例如设置 AVAudioSession 的正确模式或类似的东西?

这就是我在通过 CallKit 向系统报告调用之前准备 AVAudioSession 的方式;

        AVAudioSession *audioSession = [AVAudioSession sharedInstance];
        [audioSession setCategory:AVAudioSessionCategoryPlayAndRecord withOptions:AVAudioSessionCategoryOptionAllowBluetooth error:nil];
        [audioSession setActive:YES error:nil];

我们可以在

中配置音频会话
- (void)provider:(CXProvider *)provider performStartCallAction:(nonnull CXStartCallAction *)action

或在

- (void)provider:(CXProvider *)provider performAnswerCallAction:(nonnull CXAnswerCallAction *)action

来自音箱应用的评论,

/*  We must not start call audio here, and can only do so
 *  once the audio session has been activated by the system
 *  after having its priority elevated. So, make sure that the sound
 *  device is closed at this point.
 */

我的问题是没有激活音频会话(我有一个与之前通话的音频会话停用相关的特殊检查),因为我无法为某些通话停用音频会话。

当对方拒绝我的呼叫时,我会播放忙音,然后我会尝试使用 audioPlayerDidFinishPlaying 回调来停用音频会话。

问题是我在错误的地方设置了AVAudioPlayer委托,我必须在播放忙音之前设置它,而不是在初始化之后。
感谢 中的 post 解决了我的问题。
这是我的问题的答案,但有价值的 post 是 RJV Kumar 的答案。