我已经用CallKit实现了OpenTok。每当我开始拨出电话时,我的信息流就永远不会发布。在检查器仪表板上,它说,
尝试使用流54B02465-0E26-4AF0-8715-9D333BF6E9FC发布(尚未开始发布到会话)
它永远不会成功发布。
此外,我在日志中收到错误:
错误[OpenTok]:音频设备错误:startCapture.AudioOutputUnitStart返回错误:-66637
是否由于此错误而导致发布错误?
我已经从GitHub提供的演示中添加了OTDefaultAudioDevice文件。
下面是我的代码:
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
// Create & configure an instance of SpeakerboxCall, the app's model class representing the new outgoing call.
let call = SpeakerboxCall(uuid: action.callUUID, isOutgoing: true)
call.handle = action.handle.value
/*
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.
*/
// https://forums.developer.apple.com/thread/64544
// we can't configure the audio session here for the case of launching it from locked screen
// instead, we have to pre-heat the AVAudioSession by configuring as early as possible, didActivate do not get called otherwise
// please look for * pre-heat the AVAudioSession *
configureAudioSession()
/*
Set callback blocks for significant events in the call's lifecycle, so that the CXProvider may be updated
to reflect the updated state.
*/
call.hasStartedConnectingDidChange = {
provider.reportOutgoingCall(with: call.uuid, startedConnectingAt: call.connectingDate)
}
call.hasConnectedDidChange = {
provider.reportOutgoingCall(with: call.uuid, connectedAt: call.connectDate)
}
self.outgoingCall = call
// Signal to the system that the action has been successfully performed.
action.fulfill()
}
func provider(_ provider: CXProvider, didActivate audioSession: AVAudioSession) {
print("Received (#function)")
// If we are returning from a hold state
if answerCall?.hasConnected ?? false {
//configureAudioSession()
// See more details on how this works in the OTDefaultAudioDevice.m method handleInterruptionEvent
sendFakeAudioInterruptionNotificationToStartAudioResources();
return
}
if outgoingCall?.hasConnected ?? false {
//configureAudioSession()
// See more details on how this works in the OTDefaultAudioDevice.m method handleInterruptionEvent
sendFakeAudioInterruptionNotificationToStartAudioResources()
return
}
if outgoingCall != nil{
startCall(withAudioSession: audioSession) { success in
if success {
self.outgoingCall?.hasConnected = true
self.addCall(self.outgoingCall!)
self.startAudio()
}
}
}
if answerCall != nil{
answerCall(withAudioSession: audioSession) { success in
if success {
self.answerCall?.hasConnected = true
self.startAudio()
}
}
}
}
func sendFakeAudioInterruptionNotificationToStartAudioResources() {
var userInfo = Dictionary<AnyHashable, Any>()
let interrupttioEndedRaw = AVAudioSession.InterruptionType.ended.rawValue
userInfo[AVAudioSessionInterruptionTypeKey] = interrupttioEndedRaw
NotificationCenter.default.post(name: AVAudioSession.interruptionNotification, object: self, userInfo: userInfo)
}
func configureAudioSession() {
// See https://forums.developer.apple.com/thread/64544
let session = AVAudioSession.sharedInstance()
do {
try session.setCategory(AVAudioSession.Category.playAndRecord, mode: .default)
try session.setActive(true)
try session.setMode(AVAudioSession.Mode.voiceChat)
try session.setPreferredSampleRate(44100.0)
try session.setPreferredIOBufferDuration(0.005)
} catch {
print(#file)
print(#function)
print(error)
}
}
当我删除对OTDefaultAudioDevice的依赖关系时,一切正常,但是没有音频。
我提到了以下内容: