sinch

Sinch client won't start


Sinch client won't start and it doesn't give an error as to possible reasons.

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

Solution

  • What worked was moving Sinch and it's initialisation to the AppDelegate and making it available to other ViewControllers.

    So create the Sinch Client once

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

    And in the needed 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")
        }