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

时间:2016-07-25 16:52:27

标签: ios swift xcode sinch

我对如何正确创建SINCall对象感到困惑。我知道SINCall是一种类型的协议,在swift中我试图创建它:

var _call: SINCall?

当我尝试拨打电话时,我的应用程序崩溃,因为_call为零。

但是,如果我将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 ...

1 个答案:

答案 0 :(得分:1)

当您拨打电话时客户端是否已启动,可能需要几秒钟,因此您可能应该在启动时启动应用程序委托中的客户端,然后当客户端启动时您可以拨打电话,您可能现在为零,因为客户端没有启动