Sinch Client

The SINClient is the Sinch SDK entry point. it's used to configure the user’s and device’s capabilities, as well as providing access to feature classes such as the SINCallClient, and SINAudioController.

Creating the SINClient

Set up the client and its delegate (SINClientDelegate, see Reference documentation).

Copy
Copied
#import <Sinch/Sinch.h>

// Instantiate a Sinch client
NSError *error;
id<SINClient> sinchClient = [Sinch clientWithApplicationKey:@"<application key>"
                                            environmentHost:@"ocra.api.sinch.com"
                                                     userId:@"<user id>"
                                                      error:&error];
  • The Application Key is obtained from the Sinch Developer Dashboard - Apps .
  • The User ID should uniquely identify the user on the particular device.
  • (The term Ocra in the hostname ocra.api.sinch.com is just the name for the Sinch API that the SDK clients target)

Specifying Capabilities

The SINClient can be configured to enable specific functionality depending on your use case. To enable support for push notifications, use the method -[SINClient enableManagedPushNotifications]. Also see Push Notifications for additional steps that are required to fully implement support for push notifications.

Copy
Copied
[sinchClient enableManagedPushNotifications];

Starting the SINClient

Before starting the client, assign a SINClientDelegate. it's required to implement -[SINClientDelegate requiresRegistrationCredentials:] to Authorize the Client.

Copy
Copied
// Assign as SINClientDelegate
sinchClient.delegate = ... ;

// Start the Sinch Client
[sinchClient start];
info

If the application is meant to only make outbound calls but not receive incoming calls, the client will be ready to make calls after the delegate has received the callback clientDidStart:.

info

If the application is meant to receive incoming calls while not running in foreground, Push Notifications are required.

Authorizing the Client

When the SINClient is started with a given User ID it's required to provide a registration token to register as towards the Sinch backend.

To authorize a client, implement -[SINClientDelegate requiresRegistrationCredentials:] 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 detail in Creating a Registration Token.

The sample applications included in the Sinch SDK includes a class SINJWT that describes how to create the JWT and sign it with the Application Secret. Also see https://github.com/sinch/sinch-rtc-api-auth-examples for examples in other programming languages.

Copy
Copied
- (void) client:(id<SINClient>)client requiresRegistrationCredentials:(id<SINClientRegistration>)registrationCallback
{
  NSString *jwt = [SINJWT jwtForUserRegistrationWithApplicationKey:@"<application key>"
                                                 applicationSecret:@"<application secret>"
                                                            userId:client.userId];

  [registrationCallback registerWithJWT:jwt];
}
info

When deploying your application to production, don't embed the Application Secret in the application. The example above is only meant to show how to provide a signed JWT to the SINClient.

Life cycle Management of a SINClient-instance

We recommend that you initiate the SINClient, start it, but not terminate it, during the lifetime of the running application. That also implies that the SINClient-instance should be retained by the application code.

It's best to keep the client instance alive and started unless there are reasons specific to your application. It shouldn't be necessary to dispose of the client instance if memory warnings are received from iOS, because once the client is started it doesn't use much memory in comparison to view layers, view controllers etc. For the same reasons, if support for push notifications is enabled, the preferred method of temporarily stopping incoming calls is to Unregister a Push Device Token.

The SINClient can of course be completely stopped and also disposed. To do so, call -[SINClient terminateGracefully] before the application code releases its last reference to the client object.

Example of how to completely dispose the SINClient:

Copy
Copied
[sinchClient terminateGracefully];
sinchClient = nil;
We'd love to hear from you!
Rate this content:
Still have a question?
 
Ask the community.