# Sinch client 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). ## Creating the client Set up the client and its delegate (`SinchClientDelegate`), then instantiate a client by providing an application key, environment host, and user ID. ```swift // Keep a strong reference to sinchClient private(set) var sinchClient: SinchClient? ``` ```swift import SinchRTC do { self.sinchClient = try SinchRTC.client(withApplicationKey: "", environmentHost: "", userId: "") } catch { // Handle error } ``` - Application Key: obtain from the Sinch Developer Dashboard — Apps (https://dashboard.sinch.com/voice/apps). - Environment Host: `ocra.api.sinch.com` is the Sinch In‑app Calling API endpoint. - User ID: uniquely identifies the user on the current device. ## Specifying capabilities 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](/docs/in-app-calling/ios/push-notifications) for the full setup. ```swift sinchClient.enableManagedPushNotifications() ``` ## Starting the client Before starting the client, assign a delegate conforming to `SinchClientDelegate`. And implement the registration callback to [Authorize the Client](/docs/in-app-calling/ios/sinch-client#authorizing-the-client). ```swift // Assign delegate and start sinchClient.delegate = self sinchClient.start() ``` Delegate methods: ```swift // 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](/docs/in-app-calling/ios/push-notifications) are required. ### Authorizing the client 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](https://jwt.io/)) that's cryptographically signed with the Application Secret. How to form and sign this token is described in [Creating a Registration Token](/docs/in-app-calling/ios/auth). In the [Swift reference application on GitHub](https://github.com/sinch/rtc-reference-applications/tree/master/ios), the `SinchJWT.swift` helper demonstrates how to create and sign the JWT. ```swift 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: "", applicationSecret: "", 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. ### Life cycle management of the client instance 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: ```swift sinchClient.unregisterPushNotificationDeviceToken() ``` To completely stop and dispose of the client, terminate it gracefully and release your reference: ```swift sinchClient.terminateGracefully() sinchClient = nil ```