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 ofThreads
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 URLproviderUid
- App identifierhistoryURL
- URL of history loadingfileUploadingURL
- 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 clientid
- 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: UponclientId
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'sviewController
with specified attributes.(UIViewController *)chatViewControllerWithAttributes:(THRAttributes *)attributes completionHandler:(THROperationCompletion _Nullable)completionHandler
- Creates the chat'sviewController
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
- ExtractsAPP_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
- ReceivesThreads
bug log.(void)threads:(Threads *)threads didChangeDeviceAddress:(NSString *)deviceAddress;
- Sends a notification about the change ofdeviceAddress
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 thatCLIENT_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 setCLIENT_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 signatureCLIENT_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:name
,phone
,email
.
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.