Skip to main content
Version: 4.31.0

Advanced Settings

Logging

  • Threads.threads().attributes.logLevels = .off - Enables/disables logging. As a value, class LogLevel with support of the OptionSet(Swift) protocol or NS_OPTIONS(Objective-C) is used.

Possible values of LogLevel are as follows:

- off (all logging levels are disabled);
- info (general level);
- network (network level);
- network-sock (network level, socket);
- user-interface (user interface);
- error (all);
- all (all of the above levels are enabled);
    let logLevelValue = (LogLevel.network.rawValue | LogLevel.networkSock.rawValue)
Threads.threads().attributes.logLevels = LogLevel(rawValue: logLevelValue)

If at least one log level is enabled, the event stream is sent to the system OSLog with the "im.threads.logs" identifier and can be observed through both the XCode terminal and the Console in macOS.

Simultaneously with OSLog, events are recorded to a file on the device. Default name is Threads.log. Storage: .documentDirectory/Logs (NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true) + "/Logs"). You can forcibly disable logging to a file on the device. To do this, pass nil in the file name attribute settings:

    Threads.threads().attributes.logFileName = nil 

Settings for the log recording file on the device:

  • Threads.threads().attributes.logFileName: String? = "Threads" - Log file name, default is "Threads" (if nil is passed, logs will not be recorded to the file);
  • Threads.threads().attributes.logFileSizeMb: Int = 1 - Maximum file size in megabytes, by default - 1;
  • Threads.threads().attributes.logFileMaxCount: Int = 7 - Maximum number of log files in rotation, by default - 7. If exceeded, the oldest one will be overwritten.

ThreadsDelegate

Number of Unread Messages

- (void)threads:(Threads *)threads unreadMessagesCount:(NSUInteger)unreadMessagesCount;

Errors Processing

- (void)threads:(Threads *)threads didReceiveError:(NSError *)error;

Opening Chat upon Tapping Push Notification

To check whether the notification was opened by tapping a Threads push notification, use the isThreadsOriginPushUserInfo method:

AppDelegate.swift
extension AppDelegate: UNUserNotificationCenterDelegate {
@available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Check for application launched from notification
if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
let userInfo = response.notification.request.content.userInfo
if Threads.threads().isThreadsOriginPushUserInfo(userInfo) {
// Application launched from Threads notification
} else {
// Application launched from other notifications
}
}
completionHandler()
}
}

Programmed Message Sending

Text Message

let text = "Hello, World!"

Threads.threads().sendMessage(withText: text) { [weak self] (error) in
if let error = error {
// handle error
} else {
// handle success
}
}
note

Limitation: 4,000 characters.

Use example: TextMessageSwiftViewController.swiftTextMessageObjcViewController.m

Image

let image = UIImage(named: "helloWorld")

Threads.threads().sendMessage(with: image) { [weak self] (error) in
if let error = error {
// handle error
} else {
// handle success
}
}
note

Limit by default: 30 MB

See the use example in PictureMessageSwiftViewController.swift and PictureMessageObjcViewController.m

Using Certificates

SSL Pinning

It allows you to use a specified list of certificates to check whether they match the certificates on the server. The certificates themselves must be enclosed in the application bundle in the DER encoding. If the list is not empty, the allowUntrustedSSLCertificate setting will be ignored.

danger

When utilizing this functionality, we do not recommend using only one certificate. If it is revoked or expired, SDK will stop connecting to the server. Use backup certificates and update them timely.

  • [Threads threads].attributes.trustedCertificates - An empty array by default.
Threads.threads().attributes.trustedCertificates = [
THRCert(contentsOf: Bundle.main.url(forResource: "GUTS_2022.cer", withExtension: nil)),
THRCert(contentsOf: Bundle.main.url(forResource: "guts.2022.cer", withExtension: nil)),
THRCert(contentsOfFile: "guts_22.cer"),
THRCert(contentsOfFile: "guts.22.cer")

Working with Untrusted Certificates

It regulates validation of server certificates in the SDK. If the trustedCertificatesList setting is activated, this setting is ignored and the exact compliance of certificates from the specified list is checked.

  • [Threads threads].attributes.allowUntrustedSSLCertificate = [YES | NO] - Disabled by default.

Notifications about User Actions

  • "Threads.Controls.DidClickCloseButton" - Notification sent when the user clicks on the chat close button.

API Version

Allow to set API version for working with servers. Possible values are in enum THRAPIVersion [api15 | api17 | api18].

  • `Threads.threads.apiVersion - Default value is api15.
Threads.threads.apiVersion = THRAPIVersion.api18

Disable User Input

Disable ability of user input and sending messages to chat.

Threads.threads.disableUserInput = true