Sinch客户端无法启动

时间:2019-02-27 10:48:36

标签: sinch

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

1 个答案:

答案 0 :(得分:0)

起作用的是移动Sinch,并将其初始化到AppDelegate并将其提供给其他ViewController。

因此,一次创建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: "id@id.com")

        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")
    }