Hello 👋 How can we help?

Migrate from the iOS SDK 1.x to 2.x

This article provides a set of guidelines for migration from the HelpCrunch iOS SDK 1.x to the iOS SDK 2.x.
Written by Andrew
Updated 2 weeks ago

If you're currently using the older version of the HelpCrunch iOS SDK, you can find its documentation here. We recommend you to switch to the newer version as soon as possible, though.

Initialization

Old approach:

+ (void)initForOrganization:(NSString *)organizationDomain
             withAttributes:(NSDictionary *)attributes
          completionHandler:(HCCompletionHandler)completionHandler;

New approach:

Instead of a dictionary with keys, we moved to objects. First of all, you need to initialize the HCSConfiguration object with your organization, applicationId and applicationSecret.

+ (HCSConfiguration *)configurationForOrganization:(NSString *)organization
                                     applicationId:(NSString *)applicationId
                                 applicationSecret:(NSString *)applicationSecret;

Also, in HCSConfiguration you can configure different SDK settings like logging or setting required/optional user attributes. If you want to specify a current user, please use the HCSUser object.

+ (void)initWithConfiguration:(HCSConfiguration *)configuration
                         user:(HCSUser * _Nullable)user
                   completion:(HCSCompletionHandler _Nullable)completion;

Old approach:

+ (void)customerNameRequired:(BOOL)required;

New approach:

You can add any amount of user attributes that will be shown on a Welcome screen for new users. To do that, you should use HCSUserAttribute, where you have 4 predefined attributes and a method for adding custom attributes.

+ (HCSUserAttribute *)nameAttributeAsRequired:(BOOL)required;
+ (HCSUserAttribute *)emailAttributeAsRequired:(BOOL)required;
+ (HCSUserAttribute *)companyAttributeAsRequired:(BOOL)required;
+ (HCSUserAttribute *)phoneAttributeAsRequired:(BOOL)required;
- (HCSUserAttribute *)initWithAttributeName:(NSString *)attributeName
                                placeholder:(NSString *)placeholder
                                   required:(BOOL)required;

Create the array of attributes and pass them to HCSConfiguration’s userAttributes property before initializing the SDK.

configuration.userAttributes =
  @[[HCSUserAttribute nameAttributeAsRequired:true],
    [HCSUserAttribute companyAttributeAsRequired:true],
    [HCSUserAttribute phoneAttributeAsRequired:false],
    [[HCSUserAttribute alloc] initWithAttributeName:@"Custom required attribute"
                                        placeholder:@"My custom"
                                           required:true],
    [[HCSUserAttribute alloc] initWithAttributeName:@"Optional attribute"
                                        placeholder:@"Please enter something"
                                           required:false]];

Renaming

Old:

+ (BOOL)isShowing;

New:

+ (BOOL)isVisible;

Old:

+ (BOOL)closeChatIfVisible;

New:

+ (void)closeChatWithCompletion:(HCSCompletionHandler _Nullable)completionHandler;

Old:

+ (void)logout:(HCCompletionHandler)completionHandler;

New:

+ (void)logoutWithCompletion:(HCSCompletionHandler _Nullable)completion;

Old:

HC_SDKVersion

New:

HCSSDKVersion

Deprecated methods

+ (void)restoreFromBackground;
+ (void)useDefaultAlertForRemoteNotification:(BOOL)useDefaultAlert;
+ (void)customerNameRequired:(BOOL)required;
+ (void)enableNetworkActivityIndicator:(BOOL)enable;
+ (NSString *)appVersion;
+ (void)showFromController:(UIViewController *)controller delegate:(id)delegate;

NSNotification events

The following methods were replaced with NSNotification events.

Old:

+ (void)checkUnreadMessages:(void (^)(NSUInteger unread))callbackBlock;

New:

HCSUnreadMessagesNotification

Don't forget to check userInfo[@”data”] for NSNumber.

 Old:

HelpCrunchPresenterDelegate

The whole delegate is deprecated. Also, HC_UserClosedChatNotification was renamed.

New:

HCSUserClosedChatNotification

Old:

HC_OpenLinkNotification

New:

HCSURLNotification

Don't forget to check userInfo[@”data”] for URL.

Did this answer your question?