Search code examples
swiftvoipsinchcallkitpushkit

Sinch: user does not receive the call for the first time


I implemented Sinch + PushKit + CallKit, everything works fine, but there is one script that does not work correctly. The first user uses the application and removes it from the device's memory, the second user calls for the first time, the first user does not receive the call, if the second user immediately calls the second time, the first user receives a call (later the first user also receives a call). If the first user opens the application (that is, becomes online for the system), the first user will not receive the call again. How can I fix it?

initialization of the sinch client

open func setup() {
        guard sinch == nil else { return }
        guard let userID = UserRealmManager().getUser()?.id else { return }
        sinch = Sinch.client(withApplicationKey: key, applicationSecret: secret, environmentHost: host, userId: userID)
        sinch?.delegate = self
        sinch?.call().delegate = self

        sinch?.setSupportCalling(true)
        sinch?.enableManagedPushNotifications()
        sinch?.setSupportPushNotifications(true)

        sinch?.start()
        sinch?.startListeningOnActiveConnection()
    }

Update: I also found that if I restart the iPhone then calls through CallKit start to show up in 2-4 minutes, I decided to test it on the famous messangers such as What's app and Telegram and they have exactly the same behavior. Of course, I think it needs to be asked as an additional question.

My devices are iPhone 6 and 7.


Solution

  • This was my mistake, since I initialized SinchManager (this is the manager that manages SINClient) only in MainTabBarController viewDidLoad(), after I began to initialize it in AppDelegate didFinishLaunchingWithOptions, everything works fine.