Skip to main content
Version: 4.38.0

Migration Guide

Migration to 4.0.0

In version 4.0.0, the integration and work with the push library was reworked.

  • The MFMSPushLite library was moved inside Threads, all interaction now only occurs through it.
  • UIViewController is now provided to show the chat.

Installation via CocoaPods

If you are installing ThreadsviaCocoaPods, remove manual installation of MFMSPushLite. Now the dependency is pulled up automatically.

Threads Configuration

Replace all calls to static methods of the Threads class to address the [Threads threads] singleton.

In Application didFinishLaunchingWithOptionsbefore you register push, add the Threads configuration method. It contains MFMSPushLite configuration:

Threads *threads = [Threads threads];

[threads configureWithDelegate:self
productionMFMSServer:YES
historyURL:[NSURL URLWithString:@"HISTORY_URL"]
fileUploadingURL:[NSURL URLWithString:@"FILE_UPLOADING_URL"]];
  • From Info.plist, remove PS_API_CONFIG with the following parameters: PS_FILE_UPLOAD_URLPS_HISTORY_URLPS_CLIENTID_IS_ENCRYPTED. These parameters are no longer set in plist, only in code.

MFMSPushLiteDelegate -> ThreadsDelegate

Implementation of MFMSPushLiteDelegate replace with implementation of ThreadsDelegate and a parameter:

  • Transfer the switching of the production/test push platform from the (BOOL)isProductionWithPushApi:(MFMSPushLite * _Nonnull)pushApi method to the productionMFMSServer parameter
  • Transfer implementation of MFMSPushLiteDelegate methods
    - (id<PushServerApiConfigDataSource>)configWithPushApi:(MFMSPushLite *)pushApi;

    - (void)onPushMessagesReceivedWithPushApi:(MFMSPushLite *)PushApi messages:(NSArray<PushNotificationMessage *> *)messages;

    - (void)onErrorWithPushApi:(MFMSPushLite *)PushApi error:(NSString *)error;
    To the corresponding ThreadsDelegate methods:
    - (id<PushServerApiConfigDataSource>)threads:(Threads *)threads configurePushServerApiFor:(MFMSPushLite *)mfmsPushLite;
    - (void)threads:(Threads *)threads didReceiveFullMessages:(NSArray<PushNotificationMessage *> *)messages;
    - (void)threads:(Threads *)threads didReceiveError:(NSError *)error;

Setting up Receiving Push Notifications

Replace the push registration code:

if (@available(iOS 10, *)) {
UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
center.delegate = self;
[center requestAuthorizationWithOptions:(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge) completionHandler:^(BOOL granted, NSError * _Nullable error){
if(!error){
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] registerForRemoteNotifications];
});
}
}];
} else {
[[UIApplication sharedApplication] registerForRemoteNotifications];
}

With the following:

[Threads threads] registerApplicationForRemoteNotificationsStandartOptionsWithAuthorizationStatusDenied:^{
NSLog(@"Remote notifications denied");
} completionHandler:^(NSData * _Nullable deviceToken) {
NSLog(@"Application registered for remote notifications %@", deviceToken);
}];

Replace the implementation of methods for processing registration and receiving push messages with the following Threads calls:

- (void)application:(UIApplication *)application didRegisterUserNotificationSettings:(UIUserNotificationSettings *)notificationSettings {
[[Threads threads] applicationDidRegisterUserNotificationSettings:notificationSettings];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
[[Threads threads] applicationDidRegisterForRemoteNotificationsWithDeviceToken:deviceToken];
}

- (void)application:(UIApplication *)application didFailToRegisterForRemoteNotificationsWithError:(NSError *)error {
[[Threads threads] applicationDidFailToRegisterForRemoteNotificationsWithError:error];
}

Replace the [Threads didReceiveFullPush:...] call, now push messages are passed directly inside the library. If you use your own push notifications, you can get them in the delegate method ThreadsDelegate:

- (void)threads:(Threads *)threads didReceiveFullMessages:(NSArray<PushNotificationMessage *> *)messages;

Registering User

Remove the [Threads registerClientWithCompletion:^(BOOL state)] call, it has been deprecated.

Replace the client parameter setting:

[Threads setClientId:(NSString*) clientId]
[Threads setClientName:(NSString*) clientName]
[Threads setData:(NSString*) data]
[Threads setAppMarker: appMarker]
[Threads setClientIdSignature: (NSString*) clientIdSignature]

With the client installation method:

[[Threads threads] setClientWithId:(NSString *) clientId
name:(NSString * _Nullable) clientName
data:(NSDictionary * _Nullable) clientDataDict
appMarker:(NSString * _Nullable) clientAppMarker
signature:(NSString *) clientSignature];

Note that data is now passed as a dictionary and not a string.

Chat Opening

Replace the calls of the methods:

[Threads show];
[Threads showInView:(UIView *)view parentController:(UIViewController *)parentController;

With receiving full UIViewController that you can present in any native way, for example:

THRAttributes *attributes = [[THRAttributes alloc] init];
UIViewController *chatViewController = [[Threads threads] chatViewControllerWithAttributes:attributes];
[self.navigationController pushViewController:chatViewController animated:YES];

Other examples: Ways to Open Chat Screen

Appearance Configuration

Transfer the parameters of the chat welcome screen texts:

[Threads setHelloTitle:@"Заголовок"]
[Threads setHelloDescription:@"Описание"]

To the THRAttributes parameters:

  • helloTitle
  • helloDescription

Remove the following parameters and methods - due to transition to ViewController, they became irrelevant and were removed:

  • THRAttributes
    • navigationBarBackgroundColor
    • navigationBarTintColor
    • navigationBarItemFont
    • shouldAnimateShowNavigation
    • shouldAnimatePopNavigation
  • Threads:
    • showToolbarAnimated
    • hideToolbarAnimated
    • showKeyboard
    • hideKeyboard

Additional Capabilities

Counter of Unread Messages -> ThreadsDelegate

Transfer the processing of getting the number of unread messages from the block:

[[Threads threads] setUnreadedMessagesCountChanged:^(NSInteger messagesCount)

To implementation of the ThreadsDelegatemethod  :

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