Sinch客户端无法启动

问题描述 投票:0回答:1

Sinch客户端无法启动,并且不会出现可能原因的错误。

let uuid = UIDevice.current.identifierForVendor?.uuidString
        let client : SINClient = Sinch.client(withApplicationKey: appConstants.sinch_app_key, applicationSecret: appConstants.sinch_secret_key, environmentHost: appConstants.sinch_host, userId: uuid)
        client.setSupportCalling(true)
        //client.setSupportMessaging(true)

        client.start()
        client.delegate = self
        client.call()?.delegate = self```
sinch
1个回答
0
投票

有效的是将Sinch和它的初始化移动到AppDelegate并使其可供其他ViewControllers使用。

所以创建一次Sinch客户端

var sinchObject : SINClient!

 func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        let client : SINClient = Sinch.client(withApplicationKey: appConstants.sinch_app_key, applicationSecret: appConstants.sinch_secret_key, environmentHost: appConstants.sinch_host, userId: "[email protected]")

        client.setSupportCalling(true)
        client.setSupportMessaging(true)
        client.delegate = self
        client.start()
        sinchObject = client

        return true
    }

func applicationWillTerminate(_ application: UIApplication) {
      sinchObject?.stop()
    }

    func clientDidStart(_ client: SINClient!) {
        print("Start")
    }

    func clientDidStop(_ client: SINClient!) {
        //print("Stop")
    }

    func clientDidFail(_ client: SINClient!, error: Error!) {
        print(error.localizedDescription)
        print(error)
        print("Fail")
    }

并在所需的ViewController中

    func getSinchClient() -> SINClient {
        let mainDelegate = UIApplication.shared.delegate as! AppDelegate
        return mainDelegate.sinchObject!
    }

   func call(){
   if (getSinchClient().isStarted()){
            sinchCall = getSinchClient().call()?.callUserVideo(withId: callerId)
            sinchCall!.delegate = self
        }

    }

    func callDidProgress(_ call: SINCall!) {
        print("Call Progress")
    }

    func callDidEnd(_ call: SINCall!) {
        print("Call End")
        print(call.details.endCause.rawValue)
    }


    func callDidAddVideoTrack(_ call: SINCall!) {
        print("Call Got Video")
    }

    func callDidEstablish(_ call: SINCall!) {
         print("Call Connected")
    }
© www.soinside.com 2019 - 2024. All rights reserved.