Sinch:如何在 Swift 中设置 SINCall 变量?
Sinch: How do I set the SINCall variable in Swift?
我对如何正确创建 SINCall 对象有点困惑。我知道 SINCall 是一种类型协议,在 swift 中我尝试这样创建它:
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 ...
客户端是否在您拨打电话时启动,这可能需要几秒钟,因此您可能应该在启动时在应用程序委托中启动客户端,然后当客户端启动时您可以进行呼叫,你现在可能得到 nil 因为客户端没有启动
我对如何正确创建 SINCall 对象有点困惑。我知道 SINCall 是一种类型协议,在 swift 中我尝试这样创建它:
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 ...
客户端是否在您拨打电话时启动,这可能需要几秒钟,因此您可能应该在启动时在应用程序委托中启动客户端,然后当客户端启动时您可以进行呼叫,你现在可能得到 nil 因为客户端没有启动