ChannelIO

This class provides all necessary methods and properties in order to use Channel.

Class properties


delegate

typedescription
ChannelPluginDelegatedelegate to connect an object that implemented delegate methods

canShowLauncher

typedescription
BooleanTrue if it is appropriate to display a launch, otherwise false

Class methods


Initialize

Initialize ChannelIO. This method can be used typically in application:didLaunchWithOptions in appDelegate file.

public class func initialize(_ application: UIApplication)
+ (void)initialize:(UIApplication * _Nonnull)application

boot

Boot up ChannelIO and make it ready to use

public class func boot(with: ChannelPluginSettings, profile: Profile?=nil, completion: ((ChannelPluginCompletionStatus, User?) -> Void)?=nil)
+ (void)bootWith:(ChannelPluginSettings * _Nonnull)settings profile:(Profile * _Nullable)profile completion:(void (^ _Nullable)(enum ChannelPluginCompletionStatus, User*))completion
parametertypedescription
settingsChannelPluginSettingscontains information to boot up ChannelIO
profileProfilecontains profile information
completion(ChannelPluginCompletionStatus, User)completion block that returns status and user object
let settings = ChannelPluginSettings()
settings.pluginKey = "YOUR_PLUGIN_KEY"

ChannelPlugin.boot(with: settings) { (completion, user) in

}

let profile = Profile()
  .set(name: "guest")
  .set(mobileNumber: "01012345678")
settings.memberId = "memberId"
ChannelIO.boot(with:settings, profile: profile) { (completion, user) in

}
ChannelPluginSettings *settings = [[ChannelPluginSettings alloc] init];
[settings setPluginKey:@"YOUR_PLUGIN_KEY"];
[ChannelIO bootWith:settings profile:nil completion:^(ChannelPluginCompletionStatus status, Guest* guest) {
    
}];

Profile *profile = [[Guest alloc] init];
[profile setWithName:@"guest"];
[profile setWithMobileNumber:@"01012345678"];

[settings setMemberId:@"memberId"];
[ChannelIO bootWith:settings profile:profile completion:^(ChannelPluginCompletionStatus status, User* user) {

}];

initPushToken

initialize a device token for push notification.

public class func initPushToken(deviceToken: Data)
+ (void)initPushTokenWithDeviceToken:(NSData *)data
parametertypedescription
deviceTokenDatadevice token

Recommend to use this method in application:didRegisterForRemoteNotificationsWithDeviceToken: method in your AppDelegate

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
  ChannelIO.initPushToken(deviceToken: deviceToken)
}
- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)deviceToken {
  [ChannelPlugin initPushTokenWithDeviceToken:deviceToken];
}

shutdown

Terminate ChannelIO module

public class func shutdown()
+ (void)shutdown

open

Display ChannelIO chat messenger

public class func open(animated: Bool)
+ (void)openWithAnimated:(BOOL)animated
parametertypedescription
animatedBoolindicate to animate or not

close

Close ChannelIO chat messenger

public class func close(animated: Bool)
+ (void)closeWithAnimated:(BOOL)animated
parametertypedescription
animatedBoolindicate to animate or not

openChat

Display a chat

public class func openChat(with chatId: String? = nil, animated: Bool)
+ (void)openChatWith:(NSString * _Nullable)chatId animated:(BOOL)animated;
parametertypedescription
chatIdStringuser chat id. If it is nil, it will open lounge.

show

Display default launcher button

public class func show(animated: Bool)
+ (void)showWithAnimated:(BOOL)animated
parametertypedescription
viewUIViewa view default launcher will be displayed. Default is nil and will be displayed on current view
animatedBoolindicate to animate or not

hide

Hide default launcher button

public class func hide(animated: Bool)
+ (void)hideWithAnimated:(BOOL)animated
parametertypedescription
animatedBoolindicate to animate or not

handlePushNotification

Handle push notification

public class func handlePushNotification(_ userInfo: [AnyHashable: Any], completion: (() -> Void)? = nil)
+ (void)handlePushNotification:(NSDictionary * _Nonnull)userInfo completion:(void (^ _Nullable)completion
parametertypedescription
userInfo[Hashable: Any]push notification data
completionoptional closurecallback when finished

isChannelPushNotification

Check whether a given userInfo from push notification is belonged to Channel

public class func isChannelPushNotification(_ userInfo:[AnyHashable: Any])
+ (BOOL)isChannelPushNotification:(NSDictionary * _Nonnull)userInfo
parametertypedescription
userInfo[Hashable: Any]push notification data

handlePushNotification: and isChannelPushNotification: are typically used in userNotificationCenter:didReceiveNotificationResponse:withCompletionHandler

func userNotificationCenter(_ center: UNUserNotificationCenter,
                              didReceive response: UNNotificationResponse,
                              withCompletionHandler completionHandler: @escaping () -> Void) {
  let userInfo = response.notification.request.content.userInfo
  if ChannelPlugin.isChannelPushNotification(userInfo) {
    ChannelPlugin.handlePushNotification(userInfo)
  }
  completionHandler()
}
- (void)userNotificationCenter:(UNUserNotificationCenter *)center didReceiveNotificationResponse:(UNNotificationResponse *)response withCompletionHandler:(void (^)())completionHandler {
  NSDictionary *userInfo = response.notification.request.content.userInfo;
  if ([ChannelPlugin isChannelPushNotification:userInfo]) {
    [ChannelPlugin handlePushNotification:userInfo completion: nil];
  } 
  completionHandler();
}

track

Track an event. This method can be used various way such as tracking a page where the guest comes from.

public class func track(eventName: String, eventProperty:[String: Any]?=nil)
+ (void)trackWithEventName:(NSString * _Nonnull)eventName eventProperty:(NSDictionary<NSString *, id> * _Nullable)eventProperty;
parametertypedescription
eventNameStringname of event, its length should be less than 30
properties[String: Any]a dictionary that you want to map with this event

UpdateUser

Update user's profile values

public class func updateUser(with profile: [String: Any?], completion: ((Bool, User?) -> Void)? = nil)
+ (void)updateUser:(NSDictionary<NSString *, id> *)profile completion:(void (^ _Nullable)(BOOL success, User*))completion
parametertypedescription
profile[String: Any]a dictionary contains guest's profile key and values
completion(Bool, Guest)a tuple contains completion of update request

UpdateUser

Update user's informantion with 'UpdateUserParamBuilder'

public class func updateUser(
    param: UpdateUserParam,
    completion: ((User?, Error?) -> Void)? = nil
)
+ (void)updateUserWithParam:(NSDictionary<NSString *, id> * _Nonnull)param completion:(void (^ _Nullable)(User * _Nullable, NSError * _Nullable))completion;
parametertypedescription
paramUpdateUserParamuser's information parmams built by UpdateUserParam
completion(User, Error)a tuple contains error and user of update request

🚧

'UpdateUser' function has some different property from 'Boot' function.

  • Language
    • It is overwrite
    • Can set CHLocale values. When set null, user's language does not change.
  • Tags
    • It is overwrite
    • Tags to overwrite. Max 10 tags are allowed. Set null to reset. Empty or list with null is not allowed.
  • Profile
    • It is upsert_by_key
    • Profile map to overwrite. Set null to reset. Set null for profile value to reset profile value. Empty map is not allowed.
  • ProfileOnce
    • It is upsert_by_key
    • Map of profile to be added if there is no each profile values.

AddTags

Add user's tags

public func addTags(
  _ tags: [String], 
  completion: ((User?, Error?) -> Void)? = nil
)
+ (void)addTags:(NSArray<NSString *> * _Nonnull)tags completion:(void (^ _Nullable)(User * _Nullable, NSError * _Nullable))completion;
parametertypedescription
tags[String]a dictionary contains user's tags
completion(User, Error)a tuple contains error and user of update request

🚧

'AddTags' function has some different property from 'UpdateUser' function.

  • array
    • Tags to be added. Duplicate values are maintained. Combined tag list cannot exceed 10. Null or empty list or list with null is not allowed.

RemoveTags

Remove user's tags

public func removeTags(
  _ tags: [String], 
  completion: ((User?, Error?) -> Void)? = nil
)
+ (void)removeTags:(NSArray<NSString *> * _Nonnull)tags completion:(void (^ _Nullable)(User * _Nullable, NSError * _Nullable))completion;
parametertypedescription
tags[String]a dictionary contains user's tags
completion(User, Error)a tuple contains error and user of update request

🚧

'RemoveTags' function has some different property from 'UpdateUser' function.

  • array
    • Tags to be erased. If there is no match tag value, it is ignored. Null or empty list or list with null is not allowed.