SinchClient

public final class SinchClient

The SinchClient is the Sinch SDK entry point.

It provides access to the feature classes in the Sinch SDK: SinchCallClient and SinchAudioController and etc. It is also used to configure the user’s and device’s capabilities.

### User Identification

The user IDs that are used to identify users application specific.

Important

user IDs are restricted to the characters in “ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghjiklmnopqrstuvwxyz0123456789-_=”, and must be no longer than 255 bytes.

### Example:

 // Instantiate a client object using the client factory.
 let client = client(withApplicationKey: "<APPLICATION KEY>",
                         environmentHost: "ocra.api.sinch.com",
                         userId: "<USERID>")

 client.delegate = self
 // Enable push notifications
 client.enableManagedPushNotifications()
 // Start the client
 client.start()

 // Use SinchCallClient to place and receive calls
 client.callClient.callUser(withId:...)
  • Instance conforming to SinchClientDelegate protocol

    Declaration

    Swift

    public weak var delegate: SinchClientDelegate? { get set }
  • ID of the local user

    Declaration

    Swift

    public let userId: String
  • Check whether client is successfully started.

    Declaration

    Swift

    public var isStarted: Bool { get }

    Return Value

    A boolean value indicating whether the client has successfully started and is ready to perform calling functionality.

  • Returns the call client object for placing and receiving calls.

    Declaration

    Swift

    public let callClient: SinchCallClient
  • Retrieve the interface for the audio controller, which provides access to various audio related functionality, such as muting the microphone, enabling the speaker, and playing ring tones.

    Declaration

    Swift

    public let audioController: SinchAudioController
  • Retrieve the interface for the video controller, which provides access to video related functionality.

    Declaration

    Swift

    public let videoController: SinchVideoController
  • Start client to enable the calling functionality.

    The client delegate should be set before calling the start method to guarantee that delegate callbacks are received as expected.

    Note

    calling start after terminateGracefully will not work correctly. Client instance should be recreated instead.

    Declaration

    Swift

    public func start()
  • Terminate client when the Sinch functionality is no longer needed. Note that this will terminate the client gracefully in the sense that the client will even after this method is invoked be allowed some time to complete currently pending tasks, for example completing pending HTTP requests.

    It is strongly recommended to initiate the Sinch client, start it, but not terminate it during the lifetime of the running application. The reason is that initializing and (re-)starting the client is relatively resource intensive both in terms of CPU, as well as there is potentially network requests involved in stopping and re-starting the client.

    If desired to dispose the client, it is required to explicitly invoke terminateGracefully to relinquish certain resources. This method should always be called before the application code releases its last reference to the client.

    Declaration

    Swift

    public func terminateGracefully()
  • Specify whether this device should receive incoming calls via push notifications.

    Method should be called before calling SinchClient.start()

    Declaration

    Swift

    public func setSupportPushNotifications(supported: Bool)

    Parameters

    supported

    Enable or disable support for push notifications.

  • Specify that the Sinch SDK and platform should take care of sending the push notification to the other device via the appropriate push notification gateway (i.e. Apple Push Notification Service for iOS devices, and Firebase Cloud Messaging (FCM) for Android devices).

    (This require that you have uploaded your Apple Push Notification Certificate(s) on the Sinch website)

    This method will internally also invoke setSupportPushNotifications(supported: true)

    Method should be called before calling SinchClient.start()

    Throws

    NSInternalInconsistencyException if the method is invoked after Sinch client has already been started

    Declaration

    Swift

    public func enableManagedPushNotifications()
  • Method used to forward a push notification dictionary when using “Sinch Managed Push Notifications” (SinchClient.enableManagedPushNotifications)

    Declaration

    Swift

    @discardableResult
    public func relayPushNotification(withUserInfo userInfo: [AnyHashable : Any]) -> SinchNotificationResult

    Parameters

    userInfo

    Remote notification payload which was transferred with an Apple Push Notification.

    Return Value

    Value indicating initial inspection of push notification.

  • Register push notification device token for using “Sinch Managed Push Notifications”. The preferred way of enabling push notifications is to use SinchManagedPush which will automatically register the device token with the client, but this method can also be used directly.

    Throws

    Throws:

    • NSInternalInconsistencyException if support for push notification has not been previously enabled with (SinchClient.setSupportPushNotifications)
    • NSInvalidArgumentException if deviceToken or pushType are nil

    See also

    APSEnvironment

    Declaration

    Swift

    public func registerPushNotificationDeviceToken(_ deviceToken: Data,
                                                    forPushType type: String,
                                                    apsEnvironment: APSEnvironment)

    Parameters

    deviceToken

    A token that identifies the device to APNs.

    type

    SINPushType String constant, i.e. SinchManagedPush.TypeVoIP

    apsEnvironment

    Specification of which Apple Push Notification Service environment the device token is bound to.

  • Unregister push notification device token when using “Sinch Managed Push Notifications” Example if the user log out, the device token should be unregistered.

    Declaration

    Swift

    public func unregisterPushNotificationDeviceToken()
  • Specify a display name to be used when the Sinch client sends a push notification on behalf of the local user (e.g. for an outgoing call). This will only be used when using SinchClient.enableManagedPushNotifications().

    Display name is included in a push notification on a best-effort basis. For example, if the target device has very limited push payload size constraints (e.g iOS 7 can only handle 255 byte push notification payload), then the display name may not be included.

    Declaration

    Swift

    public func setPushNotificationDisplayName(_ displayName: String) throws

    Parameters

    displayName

    display name may at most be 255 bytes (UTF-8 encoded) long.

    Throws

    Throws if displayName exceeds 255 bytes length.