我尝试过很多使用CallKit在ios swift上发起呼出呼叫的例子。我已经在功能中启用了VOIP。在所有情况下,它都会在以下情况下失败:
callController.request(transaction) {
error in
if let error = error { print("Error requesting transaction: \(error)")}
else { print("Requested transaction successfully")
}我得到的错误是:
Error requesting transaction: Error Domain = com.apple.CallKit.error.request transaction Code=2 "(null)"我找不到与Code=2匹配的答案。
发布于 2018-12-19 18:59:24
通过简单的搜索,你可以在苹果的文档中找到所有的错误代码及其含义:https://developer.apple.com/documentation/callkit/cxerrorcoderequesttransactionerror/code
在枚举中,code=2表示unknownCallProvider是您得到的错误。描述说“控制器找不到调用提供者来执行所请求的事务中的操作”。
这里,它清楚地指定您尚未设置提供程序(CXProvider)。这就是为什么它会给出这个错误。
在CallKit的情况下,您想要发送到系统的任何操作或事务都是通过您正在使用的CXCallController完成的,系统将通过CXProvider的对象(基于您所做的配置)及其委托给出确认/操作。
现在,如果你还没有设置提供者和它的代理,系统如何与你通信呢?这就是为什么它会给出这个错误。
发布于 2018-12-20 21:22:54
在声明了一个属性callController的地方,声明另一个类型为CXProvider的属性callProvider。然后,创建对象,在其中保留这两个属性以符合CXProviderDelegate。
实现CXProvider委托的所有必要功能。当请求开始调用操作时,需要在委托方法中完成该操作,如下所示:
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {
/**
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.
*/
CallAudio.configureAudioSession()
action.fulfill()
}下面是代码摘要:
在你的班上:
private var provider: CXProvider!
private var callController: CXCallController!符合CXProvider委派:
class CallProvider: NSObject, CXProviderDelegate {创建CXProvider对象并为其分配委托:
provider = CXProvider(configuration: configuration)
provider.setDelegate(self, queue: nil) // 'nil' means it will run on main queue实现CXProvider委托函数,例如start call操作:
func provider(_ provider: CXProvider, perform action: CXStartCallAction) {}干杯!
https://stackoverflow.com/questions/53716758
复制相似问题