gpt4 book ai didi

ios - didActivate 没有被 CallKit 回调

转载 作者:搜寻专家 更新时间:2023-10-31 08:07:59 25 4
gpt4 key购买 nike

我正在将新的 CallKit API 与我的 VOIP 应用集成。

如示例应用所示:https://developer.apple.com/library/content/samplecode/Speakerbox/Introduction/Intro.html

我正在配置 Audio Session :

- (void) configureAudioSession
{
// Configure the audio session
AVAudioSession *sessionInstance = [AVAudioSession sharedInstance];

// we are going to play and record so we pick that category
NSError *error = nil;
[sessionInstance setCategory:AVAudioSessionCategoryPlayAndRecord error:&error];
if (error) {
NSLog(@"error setting audio category %@",error);
}

// set the mode to voice chat
[sessionInstance setMode:AVAudioSessionModeVoiceChat error:&error];
if (error) {
NSLog(@"error setting audio mode %@",error);
}

NSLog(@"setupAudioSession");

return;
}

在我的 CXAnswerCallAction 中:

  func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
print("Provider - CXAnswerCallAction")

// get the active call
guard let call = self.softphone.getCallForCallId(self.currentCallId) else {
action.fail()
return
}

/*
Configure the audio session, but do not start call audio here, since it must be done once
the audio session has been activated by the system after having its priority elevated.
*/
self.softphone.configureAudioSession()

// Trigger the call to be answered via the underlying network service.
call.answer()

// Signal to the system that the action has been successfully performed.
action.fulfill()
}

根据文档,didActivate 应该由 callkit 回调:

func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
print("Provider - Received \(#function)")

// Start call audio media, now that the audio session has been activated after having its priority boosted.
}

由于某些原因,它不会在第一次 VOIP 调用后回拨。随后的调用似乎收到了回调并且它们工作正常。

如何解决这个问题?

最佳答案

我通过先设置调用音频然后调用“reportNewIncomingCall”方法解决了这个问题。示例代码如下:

func reportIncomingCall(uuid: UUID, handle: String, hasVideo: Bool = false, completion: ((NSError?) -> Void)? = nil) {
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .phoneNumber, value: handle)
update.hasVideo = hasVideo


DispatchQueue.global().sync {
_ = try? AVAudioSession.sharedInstance().setCategory(AVAudioSessionCategoryPlayAndRecord, with: AVAudioSessionCategoryOptions.mixWithOthers)
_ = try? AVAudioSession.sharedInstance().overrideOutputAudioPort(AVAudioSessionPortOverride.none)
if hasVideo == true {
_ = try? AVAudioSession.sharedInstance().setMode(AVAudioSessionModeVideoChat)
} else {
_ = try? AVAudioSession.sharedInstance().setMode(AVAudioSessionModeVoiceChat)
}


do {
_ = try AVAudioSession.sharedInstance().setActive(true)
} catch (let error){
print("audio session error: \(error)")
}
}

provider.reportNewIncomingCall(with: uuid, update: update) { error in

if error == nil {

}

completion?(error as? NSError)
}
}

关于ios - didActivate 没有被 CallKit 回调,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41070739/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com