我对如何正确创建SINCall对象有些困惑。我了解SINCall是一种类型协议,因此我试图尽快创建它:

var _call: SINCall?

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

但是,如果确实将SINCall添加到SINCallDelegate和SINCallClientDelegate旁边的协议列表中,则会收到我不符合SINCall协议的错误。

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 ...

最佳答案

客户端是在调用时启动的,可能需要花费几秒钟的时间,因此启动客户端时应在应用程序委托中启动客户端,然后在客户端启动时可以进行调用,您现在可能会得到零因为客户端没有启动

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

10-09 10:00