The SinchClient (SINClient in Objective-C) is the entry point to the Sinch In‑app Calling SDK. It manages the client lifecycle and capabilities, and exposes feature APIs such as callClient (calling) and audioController (audio).
Set up the client and its delegate (SinchClientDelegate), then instantiate a client by providing an application key, environment host, and user ID.
// Keep a strong reference to sinchClient
private(set) var sinchClient: SinchClient?import SinchRTC
do {
self.sinchClient = try SinchRTC.client(withApplicationKey: "<application key>",
environmentHost: "<environment host>",
userId: "<user id>")
} catch {
// Handle error
}- Application Key: obtain from the Sinch Developer Dashboard — Apps (https://dashboard.sinch.com/voice/apps).
- Environment Host:
ocra.api.sinch.comis the Sinch In‑app Calling API endpoint. - User ID: uniquely identifies the user on the current device.
The SinchClient can be configured to enable specific functionality depending on your use case. To enable support for push notifications, use enableManagedPushNotifications(). Also see Push Notifications for the full setup.
sinchClient.enableManagedPushNotifications()Before starting the client, assign a delegate conforming to SinchClientDelegate. And implement the registration callback to Authorize the Client.
// Assign delegate and start
sinchClient.delegate = self
sinchClient.start()Delegate methods:
// SinchClientDelegate
// Provide registration credentials (JWT) for the given user
func clientRequiresRegistrationCredentials(_ client: SinchRTC.SinchClient,
withCallback callback: SinchRTC.SinchClientRegistration) {
// Obtain a signed JWT from your backend for client.userId
// callback.register(withJWT: jwt)
// or report failure:
// callback.registerDidFail(error: someError)
}
// Called when the client is ready to make outbound calls
func clientDidStart(_ client: SinchRTC.SinchClient) {}
// Called if the client failed to start
func clientDidFail(_ client: SinchRTC.SinchClient, error: Error) {}If the application should only make outbound calls and not receive incoming calls, the client is ready to make calls after clientDidStart(_:).
If the application should receive calls while not in foreground, Push Notifications are required.
When the client is started for a given user, you must provide registration credentials (a JSON Web Token) so the client can register with the Sinch backend.
To authorize a client, implement clientRequiresRegistrationCredentials(_:withCallback:) and provide a token (a JSON Web Token) that's cryptographically signed with the Application Secret. How to form and sign this token is described in Creating a Registration Token.
In the Swift reference application on GitHub, the SinchJWT.swift helper demonstrates how to create and sign the JWT.
func clientRequiresRegistrationCredentials(_ client: SinchRTC.SinchClient,
withCallback callback: SinchRTC.SinchClientRegistration) {
do {
// WARNING: Development example only. In production, fetch a JWT from your backend.
let jwt = try SinchJWT.sinchJWTForUserRegistration(withApplicationKey: "<application key>",
applicationSecret: "<application secret>",
userId: client.userId)
callback.register(withJWT: jwt)
} catch {
callback.registerDidFail(error: error)
}
}Do not embed your Application Secret in production apps. The example above is only to illustrate how to provide a signed JWT to the client during development. In production, obtain the JWT from your backend.
We recommend that you create and start a single SinchClient, and keep it alive for the lifetime of your application. This implies your code should retain a strong reference to the client instance.
It's generally best to keep the client started unless your app has specific reasons to stop it. The client uses little memory once started, so disposing it in response to generic memory warnings is usually unnecessary. Instead of terminating the client, if push notifications are enabled and you want to temporarily stop incoming calls, unregister the push device token by calling:
sinchClient.unregisterPushNotificationDeviceToken()To completely stop and dispose of the client, terminate it gracefully and release your reference:
sinchClient.terminateGracefully()
sinchClient = nil