Skip to main content
Version: 4.38.0

Methods and Properties

Methods

Integration

  • (void)configureTransportProtocolWithDelegate:(id<ThreadsDelegate> _Nullable)delegate webSocketURL:(NSURL *)webSocketURL providerUid:(NSString *)providerUid historyURL:(NSURL *)historyURL fileUploadingURL:(NSURL *)fileUploadingURL - Initial configuration of Threads with a web socket transport protocol, it needs to be called in AppDelegate. The parameters are as follows:
    • delegate - Threads delegate. Usually, it's AppDelegate.
    • webSocketURL - Web socket URL
    • providerUid - App identifier
    • historyURL - URL of history loading
    • fileUploadingURL - URL of uploading files
  • (void)configureWithDelegate:(id<ThreadsDelegate> _Nullable)delegate productionMFMSServer:(BOOL)productionMFMSServer historyURL:(NSURL *)historyURL fileUploadingURL:(NSURL *)fileUploadingURL -
  • (void)registerApplicationForRemoteNotificationsStandartOptionsWithAuthorizationStatusDenied:(void (^)(void))authorizationStatusDenied completionHandler:(THRRemoteNotificationsRegistrationCompletion _Nonnull)completionHandler - App registration on the APNS server. The parameters are as follows:
    • authorizationStatusDenied - The block that processes it when users choose to refuse receiving push notifications.
    • completionHandler - App registration completion block on the APNS server.

Methods of Registration and Processing Notifications

Following are methods of registration and processing notifications, they must be only called in the respective methods of AppDelegate.

- (void)applicationDidRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings;
- (void)applicationDidRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken;

Working with Clients

  • (void)setClientWithId:(NSString *)id name:(NSString * _Nullable)name appMarker:(NSString * _Nullable)appMarker signature:(NSString *)signature; - Configuring a client
    • id - Unique client ID. This parameter is required.
    • name - Client's name. This parameter is optional.
    • appMarker - Chat identifier. This parameter is optional, it must be only used for multi-chat. Any unique string can be used as APP_MARKER. APP_MARKER must be the same for the corresponding Android and iOS apps.
    • signature - Authorization signature clientId. Currently, this parameter is optional, verification is enabled on the Threads server. The signature must be generated on your authorization server based on clientId using the RSA private key, then encrypted in Base64. For the general scheme of working with the signature, refer to the backend documentation.
  • (void) logout - Log out the current client - the app will stop receiving messages for this client. Important: Upon clientId change, automatic logout is not executed.
  • (void) logout: (NSString*) clientId - Log out a client with a specific identifier.

Creating Chat Screen

  • (UIViewController *)chatViewControllerWithAttributes:(THRAttributes *)attributes - Creates the chat's viewController with specified attributes.
  • (UIViewController *)chatViewControllerWithAttributes:(THRAttributes *)attributes completionHandler:(THROperationCompletion _Nullable)completionHandler - Creates the chat's viewController with specified attributes and the chat initialization success handler.

Tools

  • (NSString *) version - Returns the version of the Threads library
  • (void) clearCachedFiles - Clears the local image cache
  • (BOOL) isThreadsOriginPushUserInfo:(NSDictionary *)userInfo - Verifies whether the push notification belongs toThreads
  • (NSString *) getAppMarkerFromPushUserInfo:(NSDictionary *)userInfo - Extracts APP_MARKER from the push notification

Programmed Message Sending

  • (void)sendMessageWithText:(NSString *)text completion:(nullable THROperationCompletion)completion - Sends a test message
  • (void)sendMessageWithImage:(UIImage *)image completion:(nullable THROperationCompletion)completion - Sends an image

ThreadsDelegate

  • (void)threads:(Threads *)threads unreadMessagesCount:(NSUInteger)unreadMessagesCount - Receives the number of unread messages.
  • (void)threads:(Threads *)threads didReceiveError:(NSError *)error - Receives Threads bug log.
  • (void)threads:(Threads *)threads didChangeDeviceAddress:(NSString *)deviceAddress; - Sends a notification about the change of deviceAddress including when it's first received after the successful registration on push notifications.

Properties

Configuration

  • id <ThreadsDelegate> delegate - Threads delegate. Usually, it's AppDelegate.
  • BOOL isClientIdEncrypted - Flag indicating that CLIENT_ID is passed encrypted.
  • BOOL isShowsNetworkActivity - Parameter for showing network activity in the status bar.
  • NSInteger fileSizeLimit - Size limitations (in bytes) for files to upload.
  • THRAttributes *attributes - Chat behavior and display settings. See documentation.

Client

  • NSString *clientId - Current set CLIENT_ID.
  • NSString *clientName - Name of the current client.
  • NSString *appMarker - App marker. It is used to connect several apps to the same server or implement several chats in the same app.
  • NSString *clientSignature - Authorization signature CLIENT_ID. The signature must be generated on your authorization server based on clientId using the RSA private key, then encrypted in Base64.
  • NSString *data - JSON string with custom client data. The following parameters will be displayed in general client info: namephoneemail.

Example:

    {
"name": "Name Surname",
"phone": "+7-999-999-99-99",
"email": "e@mail.com",
"customField":"customValue"
}

State

  • BOOL isClientSet - The parameter that indicates whether the client is specified in the chat.
  • NSInteger unreadMessagesCount - Number of unread messages.