gpt4 book ai didi

ios - Sinch:如何在 Swift 中设置 SINCall 变量?

转载 作者:行者123 更新时间:2023-11-29 00:46:16 25 4
gpt4 key购买 nike

我对如何正确创建 SINCall 对象有些困惑。我知道 SINCall 是一种类型协议(protocol),我很快就尝试这样创建它:

var _call: SINCall?

当我尝试调用时,我的应用程序崩溃了,因为 _call 为 nil。

但是,如果我将 SINCall 添加到 SINCallDelegate 和 SINCallClientDelegate 旁边的协议(protocol)列表中,我会收到错误消息,指出我不符合 SINCall 协议(protocol)。

class CallViewController: UIViewController, SINCallDelegate, SINCallClientDelegate {

var userName: String? {
didSet {

}
}
var recepientUser: String? {
didSet {

}
}

var _call: SINCall?

var appKey = "xxx"
var appSecret = "xxx"
var host = "xxx"

var client: SINClient {
return Sinch.clientWithApplicationKey(appKey, applicationSecret: appSecret, environmentHost: host, userId: userName!)

}

override func viewDidLoad() {
super.viewDidLoad()
print("Lock and load")

client.callClient().delegate = self
client.setSupportCalling(true)
client.start()
client.startListeningOnActiveConnection()

callUser()
}

func callUser() {
self._call = client.callClient().callUserWithId(self.recepientUser!)
self._call!.delegate = self
}

func client(client: SINCallClient!, didReceiveIncomingCall call: SINCall!) {
call.delegate = self
self._call = call
self._call!.answer()
}

// callDidProgress, callDidEstablish, callDidEnd implemented below ...

最佳答案

调用时客户端是否启动,这可能需要几秒钟,所以您可能应该在启动时在应用程序委托(delegate)中启动客户端,然后当客户端启动时您可以进行调用,您可能现在得到 nil 因为客户端没有启动

关于ios - Sinch:如何在 Swift 中设置 SINCall 变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38573447/

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